Forum Index > Projects > Micro-readerboard project support
 alphanumeric led display with arduino?
 |  Printable Version
By: Leviathan34 (offline) on Monday, November 30 2009 @ 08:26 AM PST  
Leviathan34

Can somebody please give me some advice or something? I really need help here!


Forum Henchperson
Henchperson

Status: offline

Registered: 11/15/09
Posts: 20

Profile Email    
   
By: Windell (offline) on Monday, November 30 2009 @ 09:20 AM PST  
Windell

Last I heard, you didn't need serial or ICSP in your project, so you just needed to hook up the appropriate digital I/O lines with some resistors and transistors, and you had figured out how to do it... except that maybe you decided to change your mind and try some irrelevant things (like analogWrite). I'm not sure what you're asking. Shouldn't you go back and do it digitally, as you had already intended to?


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Leviathan34 (offline) on Sunday, December 06 2009 @ 11:33 AM PST  
Leviathan34

Alright, this time I've figured it out for real. It turns out that you can use the analog pins as general I/O pins. Big Grin Problem solved!

As for the analogWrite thing, I was confused about the function of analogWrite. But now I finally figured it out.

Thanks for the help guys.


Forum Henchperson
Henchperson

Status: offline

Registered: 11/15/09
Posts: 20

Profile Email    
   
By: Leviathan34 (offline) on Sunday, December 06 2009 @ 07:13 PM PST  
Leviathan34

Okay so I figured out how I'm going to do it but I've hit a snag with the programming............it doesn't work right.

Here's the finished code.
I don't know what part is wrong, but it's probably in 'void charAssign.'
If you could please take a look at it and see if you can tell what is wrong. (btw, I know it's probably not the best or the most efficient code, but only learned how to program 2 years ago when I was in 7th grade)

#define MAX_MILLIS_VALUE 34359738
unsigned long m = 0;
int ledA = 0;
int ledB = 1;
int ledC = 2;
int ledD = 3;
int ledE = 4;
int ledF = 5;
int ledG1 = 6;
int ledG2 = 7;
int ledI = 9;
int ledL = 12;
int hours = 1;
int tens = 0;
int ones = 0;
int displayAssign;
int displayVal;
unsigned long previousMillis;
unsigned long currentMillis;

void clock() {
currentMillis = millis();
if (currentMillis < previousMillis) // if millis overflows
{
m += MAX_MILLIS_VALUE - previousMillis + currentMillis;
}
else // if millis has not overflown
{
m += currentMillis - previousMillis;
}currentMillis = millis();
if (m>59000) {
ones++;
m = m - 60000;
}
if (ones > 15) {
tens++;
ones = 0;
}
if (tens > 3) {
hours++;
tens = 0;
}
if (hours > 12) {
hours = 0;
}
}

void reset() {
digitalWrite(ledA, LOW); // resets led display to avoid character conflicts and overlaps.
digitalWrite(ledB, LOW);
digitalWrite(ledC, LOW);
digitalWrite(ledD, LOW);
digitalWrite(ledE, LOW);
digitalWrite(ledF, LOW);
digitalWrite(ledG1, LOW);
digitalWrite(ledG2, LOW);
digitalWrite(ledI, LOW);
digitalWrite(ledL, LOW);
digitalWrite(17, LOW);
digitalWrite(18, LOW);
digitalWrite(19, LOW);
}

void charAssign() {
if (displayAssign == 17) {
displayVal = hours;
} else {
if (displayAssign == 18) {
displayVal = tens;
} else {
if (displayAssign == 19) {
displayVal = ones;
}
}
}
switch (displayVal) { // Determine what the value of displayVal is and display the appropriate character.
// if displayVal is 0, display a 0.
case 0: digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledE, HIGH); digitalWrite(ledF, HIGH); break;
// if displayVal is 1, display a 1, etc.
case 1: digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); break;
case 2: digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledE, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
case 3: digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
case 4: digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledF, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
case 5: digitalWrite(ledA, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledF, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
case 6: digitalWrite(ledA, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledE, HIGH); digitalWrite(ledF, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
case 7: digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); break;
case 8: digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledE, HIGH); digitalWrite(ledF, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
case 9: digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledF, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
// if displayVal is 10, display an A, etc.
case 10: digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledE, HIGH); digitalWrite(ledF, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
case 11: digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledG2, HIGH); digitalWrite(ledI, HIGH); digitalWrite(ledL, HIGH); break;
case 12: digitalWrite(ledA, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledE, HIGH); digitalWrite(ledF, HIGH); break;
case 13: digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); digitalWrite(ledC, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledI, HIGH); digitalWrite(ledL, HIGH); break;
case 14: digitalWrite(ledA, HIGH); digitalWrite(ledD, HIGH); digitalWrite(ledE, HIGH); digitalWrite(ledF, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
case 15: digitalWrite(ledA, HIGH); digitalWrite(ledE, HIGH); digitalWrite(ledF, HIGH); digitalWrite(ledG1, HIGH); digitalWrite(ledG2, HIGH); break;
}
}

void displayLED() {
for( displayAssign = 17; displayAssign < 20; displayAssign++) {
reset();
digitalWrite(displayAssign, HIGH);
charAssign();
}
}

void setup() {
pinMode(ledA, OUTPUT);
pinMode(ledB, OUTPUT);
pinMode(ledC, OUTPUT);
pinMode(ledD, OUTPUT);
pinMode(ledE, OUTPUT);
pinMode(ledF, OUTPUT);
pinMode(ledG1, OUTPUT);
pinMode(ledG2, OUTPUT);
pinMode(ledI, OUTPUT);
pinMode(ledL, OUTPUT);
pinMode(17, OUTPUT); // turns on an NPN transistor to select the hours display
pinMode(18, OUTPUT); // turns on the tens digit display (technically the 16's display since it's hex)
pinMode(19, OUTPUT); // turns on the ones display
}

void loop() {
clock();
displayLED();
}


Forum Henchperson
Henchperson

Status: offline

Registered: 11/15/09
Posts: 20

Profile Email    
   
By: Leviathan34 (offline) on Monday, December 07 2009 @ 02:36 PM PST  
Leviathan34

Hey, sorry for that grossly huge post.

I fixed the display part of the code but now it is going WAAAAY too fast. Like 10 minutes on the clock for every second in real time.

I mad a slight modification to the clock function, here it is: (btw, the reason that tens only goes up to 3 is because 3B in Hex is equal to 59 in decimal, but you guys probably already knew that.)

PHP Formatted Code
void clock() {
  currentMillis = millis();
  if (currentMillis < previousMillis) // if millis overflows
  {
    m += MAX_MILLIS_VALUE - previousMillis + currentMillis;
  }
  else // if millis has not overflown
  {
    m += currentMillis - previousMillis;
  }currentMillis = millis();
  if (m > 999) {
    seconds++;
    m = m - 1000;
  }
  if (seconds > 59) {
    ones++;
    seconds = 0;
  }
  if (ones > 15) {
    tens++;
    ones = 0;
  }
  if (tens > 3) {
    hours++;
    tens = 0;
  }
  if (hours > 12) {
    hours = 1;
  }
}


Forum Henchperson
Henchperson

Status: offline

Registered: 11/15/09
Posts: 20

Profile Email    
   
By: Windell (offline) on Monday, December 07 2009 @ 02:46 PM PST  
Windell

I might suggest that you only want to call millis() ONCE in your loop, to avoid possible error buildup. Also, are you actually setting previousMillis anywhere?


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Leviathan34 (offline) on Monday, December 07 2009 @ 03:06 PM PST  
Leviathan34

Oh yeah, woops. I did forget to set previousMillis. That weird cause I swear I had that in there.

Okay it's working now, thanks a lot! Big Grin


Forum Henchperson
Henchperson

Status: offline

Registered: 11/15/09
Posts: 20

Profile Email    
   



 All times are PDT. The time is now 10:59 PM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

Evil Mad Scientist Forum Archives — Read only!

Please visit our new forums for new discussions.


DIY Hardware for Electronic Art


The Original Egg-Bot Kit


Octolively
Interactive LED kits


Meggy Jr RGB
LED matrix game
development kit.


Business-card sized
AVR target boards


Peggy 2
LED Pegboard kits

My Account






Lost your password?