int button
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
button 4;
pinMode(4=INPUT);
}
void loop()
{
if(digitalRead(4)== LOW);
{
digitalWrite (13, HIGH);
delay (250);
digitalWrite (13, LOW);
digitalWrite (12, HIGH);
delay (250);
digitalWrite (12, LOW);
}
}
-
I need help, im new on this and i want to try something like Press button to start LOOP but it didtn work. it still telling me :4:1: error: expected initializer before 'void' and 4:1: error: expected initializer before 'void' but i still cant find a mistake on code.DeePee– DeePee2019-11-24 14:01:33 +00:00Commented Nov 24, 2019 at 14:01
-
1You are missing a semicolon after the button declarationchrisl– chrisl2019-11-24 14:13:32 +00:00Commented Nov 24, 2019 at 14:13
-
2Please don't post photos of the code editor, that's not useful. Paste your code in with at least four spaces ahead of each line to retain the formatting.Dougie– Dougie2019-11-24 14:15:23 +00:00Commented Nov 24, 2019 at 14:15
Add a comment
|
1 Answer
There's significant syntax errors in your code. I think I've caught them all.
//int button;
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
// button 4;
pinMode(4, INPUT);
}
void loop() {
if (digitalRead(4) == LOW) {
digitalWrite (13, HIGH);
delay (250);
digitalWrite (13, LOW);
digitalWrite (12, HIGH);
delay (250);
digitalWrite (12, LOW);
}
}
-
NICE!! Thank you, I can finally start simulation. But do you know why the leds are always on? The leds doesnt react to button.DeePee– DeePee2019-11-24 14:23:38 +00:00Commented Nov 24, 2019 at 14:23
-
1@Deepee: The button-input needs a pullup resistor to keep it HIGH when the button is not pressed. The easiest way to add one is to make
pinMode(4, INPUT);readpinMode(4, INPUT_PULLUP);instead. This uses an internal pullup provided by the MCU and saves you having to install one on your board.JRobert– JRobert2019-11-24 14:57:01 +00:00Commented Nov 24, 2019 at 14:57 -
@JRobert Thanks :) . U solved my problem.DeePee– DeePee2019-11-24 15:13:30 +00:00Commented Nov 24, 2019 at 15:13
-
Also good to note about the commented out and unused
button 4;: if you want to assign 4 to the variablebutton, you use the=operator, sobutton = 4;bdbdbd– bdbdbd2019-11-24 17:53:29 +00:00Commented Nov 24, 2019 at 17:53

