-1

enter image description here

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);
  }
 }

enter image description here

3
  • 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. Commented Nov 24, 2019 at 14:01
  • 1
    You are missing a semicolon after the button declaration Commented Nov 24, 2019 at 14:13
  • 2
    Please 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. Commented Nov 24, 2019 at 14:15

1 Answer 1

0

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);
     }
   }
4
  • NICE!! Thank you, I can finally start simulation. But do you know why the leds are always on? The leds doesnt react to button. Commented 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); read pinMode(4, INPUT_PULLUP); instead. This uses an internal pullup provided by the MCU and saves you having to install one on your board. Commented Nov 24, 2019 at 14:57
  • @JRobert Thanks :) . U solved my problem. Commented 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 variable button, you use the = operator, so button = 4; Commented Nov 24, 2019 at 17:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.