Hi all, I'm working on an Arduino project to control a set of LED tail lights in a car part by part, and I'm having some difficulty getting my sketch to achieve the desired result. I've been reading tutorials on basic Arduino functions of all sorts for months now (not specifically on this project, but I've been trying to learn to code on it for some time) yet I still can't get what is seemingly a very simple piece of code to work! I've managed to get some very basic sketches working, but this problem is alluding me...
Simply put, the sketch is meant to check if pins 7,8,9 are high or low, and set the other pins (optically isolated and driving power fets) to follow what the inputs are doing. Should be simple, just some if, else statements and that's it, but at the moment I'm not getting any of my outputs going high regardless what I set the input pin(s) to. Before anyone asks, I've tested the hardware by just feeding in 5v and gnd to the optos, and they drive the led strips just fine.
My code is at the bottom of the post, it should be possible to directly paste into arduino ide. I haven't commented much of it because it is fairly self-explanatory, I would hope.
I hope that someone can point me in the right direction! Please ask if you need anymore details to help me out
int brakeLightOne = 2; //init outputs on D2-D6
int brakeLightTwo = 3;
int brakeLightThree = 4;
int turnLight = 5;
int reverseLight = 6;
int brakeInput = 7; //init inputs on D7,D8,D9
int turnInput = 8;
int reverseInput = 9;
void setup()
{
pinMode(brakeLightOne, OUTPUT); //setting light pins (2-6) as outputs
pinMode(brakeLightTwo, OUTPUT);
pinMode(brakeLightThree, OUTPUT);
pinMode(turnLight, OUTPUT);
pinMode(reverseLight, OUTPUT);
pinMode(brakeInput, INPUT); //setting input pins (D7,D8,D9) as inputs
pinMode(turnInput, INPUT);
pinMode(reverseInput, INPUT);
}
void loop()
{
if (brakeInput == HIGH) {
digitalWrite(brakeLightOne, HIGH);
//delay(500);
digitalWrite(brakeLightTwo, HIGH);
//delay(500);
digitalWrite(brakeLightThree, HIGH);
//delay(500);
}
else{
digitalWrite(brakeLightOne, LOW);
//delay(500);
digitalWrite(brakeLightTwo, LOW);
//delay(500);
digitalWrite(brakeLightThree, LOW);
//delay(500);
}
if (turnInput == HIGH) {
digitalWrite(turnLight, HIGH);
//delay(500);
}
else{
digitalWrite(turnLight, LOW);
//delay(500);
}
if (reverseInput == HIGH) {
digitalWrite(reverseLight, HIGH);
//delay(500);
}
else{
digitalWrite(reverseLight, LOW);
//delay(500);
}
delay(5);
}