I am working on Arduino to create something of a practice project for myself.
I have columns lined up, one red and one blue. Each have three LED lights in them. At the end of the circuit I have three LEDs that I want to light up when one column is lit up.
I have tried doing this with Arrays and just can't seem to figure it out. Pictures are attached of the board. Picture 1844 is of the three blue LEDS on. The problem is, I ONLY want the last three LEDs to light up when all three of one colour are lit. I can't seem to upload the picture to show you, but that doesn't appear to be happening
I have also attached my code
I would greatly appreciate an answer 
Thank you!
Erin
PinArrays.ino (487 Bytes)
Arrays aren't needed, but would work...
something like this::
void loop() {
if (digitalRead(redSide[0]) == HIGH && digitalRead(redSide[1]) == HIGH && digitalRead(redSide[2]) == HIGH) {
digitalWrite(smile, HIGH);
} else {
digitalWrite(smile, LOW);
}
}
note that redSmile[3] points to the 4th integer in the redSmile array, but in this case there isn't one, since the max size of the array was defined as 3.
int redSide[3] = {2, 4, 6};
int blueSide[3] = {3, 5, 7};
int smile = 8;
should be
const byte redSide[] = {2, 4, 6}; //const because pins don't change, they are constant. byte to save memory.
const byte blueSide[] = {3, 5, 7};
const byte smile = 8;
and also,
void setup() {
// initialize digital pin 13 as an output.
pinMode(redSide[3], OUTPUT);
pinMode(blueSide[3], OUTPUT);
pinMode(smile, OUTPUT);
}
you can't set the pins to output like that. needs to be:
void setup() {
// initialize digital pin 13 as an output.
for(int i = 0, i < 3; i++){
pinMode(redSide[i-1], OUTPUT);
pinMode(blueSide[i-1], OUTPUT);
pinMode(smile, OUTPUT);
}
}
Qdeathstar:
void setup() {
// initialize digital pin 13 as an output.
for(int i = 0, i < 3; i++){
pinMode(redSide[i-1], OUTPUT);
pinMode(blueSide[i-1], OUTPUT);
pinMode(smile, OUTPUT);
}
}
This won't work because it will go outside it's boundaries (-1...). Also you should place the pinmode (smile,output) outside the loop as it has to be set only once. This should work
void setup() {
// initialize digital pin 13 as an output.
for(int i = 0, i < 3; i++){
pinMode(redSide[i], OUTPUT);
pinMode(blueSide[i], OUTPUT);
}
pinMode(smile, OUTPUT);
}
Also just a small note, you can leave away the comparison " == HIGH" @ digitalread to make it a little bit neater to the eye :).