I wrote the code below to control a 7-segment LED
my main questions is about using the LED variable
//Lets try and light up a 7 segment LED
int g = 2; // LED connected to digital pin 1
int f = 1; // LED connected to digital pin 2
int e = 3; // LED connected to digital pin 3
int d = 4; // LED connected to digital pin 4
int c = 5; // LED connected to digital pin 5
int b = 6; // LED connected to digital pin 6
int a = 7; // LED connected to digital pin 7
int dot = 8; //LED connected to the digital pin 8
int LED[]={0,1,1,0,0,0,0,0}; //This is the array that tells each pin in the LED to turn on
int val = 9;
void setup() // run once, when the sketch starts
{
pinMode(g, OUTPUT); // sets the digital pin as output
pinMode(f, OUTPUT); // sets the digital pin as output
pinMode(e, OUTPUT); // sets the digital pin as output
pinMode(d, OUTPUT); // sets the digital pin as output
pinMode(c, OUTPUT); // sets the digital pin as output
pinMode(b, OUTPUT); // sets the digital pin as output
pinMode(a, OUTPUT); // sets the digital pin as output
pinMode(dot,OUTPUT);
pinMode(13,OUTPUT);
}
void loop() // run over and over again
{
// int val = 9;
if (val==9) {
int LED[] = {1, 1, 1, 0, 0, 1, 1, 0};
}
if (val==8) {
int LED[] = {1, 1, 1, 1, 1, 1, 1, 0 };
}
if (val==7) {
int LED[] = {1, 1, 1, 0, 0,0, 0, 0};
}
if (val==6) {
int LED[] = {0, 0, 1, 1, 1, 1, 1, 0 };
}
if (val==5) {
int LED[] = {1, 0, 1, 1, 0, 1, 1, 0};
}
if (val==4) {
int LED[] = {0, 1, 1, 0, 1, 1, 1, 0};
}
if (val==3) {
int LED[] = {1, 1, 1, 1, 0, 0, 1, 0};
}
if (val==2) {
int LED[] = {1, 0, 1, 1, 0, 1, 1, 0};
}
if (val==1) {
int LED[] = {0, 1, 1, 0, 0, 0, 0, 0 };
}
if (val==0) {
int LED[] = {1, 1, 1, 1, 1, 1, 0, 0};
}
digitalWrite(g, LED[6]); // sets the LED on
digitalWrite(f, LED[5]); // sets the LED on
digitalWrite(e, LED[4]); // sets the LED on
digitalWrite(d, LED[3]); // sets the LED on
digitalWrite(c, LED[2]); // sets the LED on
digitalWrite(b, LED[1]); // sets the LED on
digitalWrite(a, LED[0]); // sets the LED on
}
at this stage of my code development, I want to be able to change "val" and have it look in the correct "if" statement and make "LED" a new array. However now "LED" never changes from what I initialize it as. In the above case, my 7-segment LED stays as a "1", even though "val=9" and the 7-seg should show 9.
I've checked my hardware, I need some simple help.