Hi all,
Just got one of these and learning programming and trying to use a 7-segment LED to count from 1 to 8. I can do it fine without using arrays or for statements but it's incredibly long and inefficient code so I found the array and for commands and figured they can do the job. My issue is that it's not counting correctly. If I limit the code to only display one of the numbers individually, it displays it correctly, however if I try a sequence it gives me jumbled rubbish.
One thing I've noticed is that the digits it does give appear to be a combination of the previous and current number of the sequence. I feel I'm missing something silly.
//This code will light up the 7 segment LED from A to G 1 by 1
const int timer=5000; //Sets the delay time
int LED1[2]= {7,6};
int LED2[5]= {8,7,2,4,5};
int LED3[5]= {8,7,2,6,5};
int LED4[4]= {7,6,2,3};
int LED5[5]= {8,3,2,6,5};
int LED6[5]= {6,5,4,3,2};
int LED7[3]= {8,7,6};
int LED8[7]= {8,7,6,5,4,3,2};
void setup(){
for(int Pin=0;Pin<=8;Pin++)
pinMode(Pin,OUTPUT);
}
void loop(){
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED1],HIGH);
delay(timer);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED1],LOW);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED2],HIGH);
delay(timer);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED2],LOW);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED3],HIGH);
delay(timer);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED3],LOW);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED4],HIGH);
delay(timer);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED4],LOW);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED5],HIGH);
delay(timer);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED5],LOW);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED6],HIGH);
delay(timer);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED6],LOW);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED7],HIGH);
delay(timer);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED7],LOW);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED8],HIGH);
delay(timer);
for(int Pin=0; Pin<=8;Pin++)
digitalWrite(Pin[LED8],LOW);
}
LED_7Seg_Count.ino (1.63 KB)