Hello all. I am very new to hobbyist electronics and fairly new to programming. I have the Uno starter kit from Elegoo and have been working through the Paul McWhorter Arduino playlist on YouTube. I just finished the binary numbers video, and the assignment he gave is to wire up 4 LEDs (this part is done and working correctly), and then to write a program that will count from 0-15 in binary using said LEDs. My approach with this Arduino course is to figure out these projects before moving to the next video. The sketch I created is what I thought would work most efficiently and dynamically (in case I want to make changes), instead of just a bunch of copy-pasted lines of digital writes and then delays.
The issue I'm having is, when I upload to the board or press the button to restart, all 4 LEDs light up and stay lit indefinitely. I have almost no C++ experience, so perhaps I'm not using proper syntax or not using the arrays correctly. I will paste my code below, and I'm sure many of you will very quickly see what I'm doing wrong. Also, I'm very sorry if any formatting looks off, specifically indentation. If it is please let me know because I am very open to criticism and learning.
On a side note, I would like to accelerate my learning timeline when it comes to C++. I love Paul's videos so far, but I do not want to solely rely on them for the coding aspect so that I can be more confident in my solutions for these course projects. Is learncpp.com a resource that you would recommend?
int loopCounter = 0;
int loopDelay = 1500;
int writeValueLed1 = "LOW";
int writeValueLed2 = "LOW";
int writeValueLed3 = "LOW";
int writeValueLed4 = "LOW";
int ledPin1 = 10;
int ledPin2 = 11;
int ledPin3 = 12;
int ledPin4 = 13;
int numArray1[8] = {0,2,4,6,8,10,12,14};
int numArray2[8] = {0,1,4,5,8,9,12,13};
int numArray3[8] = {0,1,2,3,8,9,10,11};
int numArray4[8] = {0,1,2,3,4,5,6,7};
bool match1 = false;
void setup() {
// put your setup code here, to run once:
pinMode(ledPin1,OUTPUT);
pinMode(ledPin2,OUTPUT);
pinMode(ledPin3,OUTPUT);
pinMode(ledPin4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
for(int i = 0; i < 8; i++) {
if(numArray1[i] == loopCounter) {
match1 = true;
break;
}
}
if(match1) {
writeValueLed1 = "LOW";
}
else {
writeValueLed1 = "HIGH";
}
match1 = false;
for(int i = 0; i < 8; i++) {
if(numArray2[i] == loopCounter) {
match1 = true;
break;
}
}
if(loopCounter == numArray2) {
writeValueLed2 = "LOW";
}
else {
writeValueLed2 = "HIGH";
}
match1 = false;
for(int i = 0; i < 8; i++) {
if(numArray3[i] == loopCounter) {
match1 = true;
break;
}
}
if(loopCounter == numArray3) {
writeValueLed3 = "LOW";
}
else {
writeValueLed3 = "HIGH";
}
match1 = false;
for(int i = 0; i < 8; i++) {
if(numArray4[i] == loopCounter) {
match1 = true;
break;
}
}
if(loopCounter == numArray4) {
writeValueLed4 = "LOW";
}
else {
writeValueLed4 = "HIGH";
}
match1 = false;
digitalWrite(ledPin1,writeValueLed1);
digitalWrite(ledPin2,writeValueLed2);
digitalWrite(ledPin3,writeValueLed3);
digitalWrite(ledPin4,writeValueLed4);
delay(loopDelay);
if(loopCounter == 15) {
loopCounter = 0;
}
else {
loopCounter = loopCounter + 1;
}
}
