This is my code but for some reason the LEDs don't light up at all and the loop at the very end does 'not name a type'
'''''''''''''''''''''''''''''''''''''''''''''''
int switchState = 0;
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
switchState = digitalRead(2);
// this is a comment
if (switchState== LOW) {
// button pressed
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
else { // button pressed
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); //this will slow down the leds
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
} loop
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Welcome to the forum
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
just_a_c0d3r:
} loop
Did you mean that to be a comment indicating the end of the loop() function? that would be:
} // loop
I'm pretty sure it just means to loop all the code from void loop
code but idk
ps i tried
else { // button pressed
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); //this will slow down the leds
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
} // loop
@johnwasser
the LEDs don't even light up...
PaulRB
February 16, 2022, 8:45am
7
It doesn't. It's not valid C and that's why you got the error message.
just_a_c0d3r:
ps i tried
And what happened then?
The LEDs will not light until your code has been compiled and uploaded to the Arduino.
@PaulRB
The LEDs don't light up
actually I think I've got it. i frogot to write in the second delay
I'm in a brightly lit room so maybe they're just dim?
PaulRB
February 16, 2022, 8:50am
10
So your sketch is now compiling without error and uploaded to the Arduino? Post the updated code please. If you still need help, be sure to use code tags as you were asked to do. You have still not corrected your original post by adding the code tags there.
@PaulRB
the LEDs still don't turn on...
int switchState = 0;
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
switchState = digitalRead(2);
// this is a comment
if (switchState== LOW) {
// button pressed
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
else { // button pressed
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); //this will slow down the leds
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); //slow it down again
}
} // loop
PaulRB
February 16, 2022, 8:53am
12
Thanks for using code tags.
I would expect at least one led to light. Please post a schematic.
sorry, accidentally deleted this comment.
do you mean a photo of the setup?
PaulRB
February 16, 2022, 6:18pm
18
It might help, but a schematic drawing would be much clearer. Hand drawn will be ok.
system
Closed
August 15, 2022, 6:19pm
19
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.