-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.
    – DeePee
    Nov 24 '19 at 14:01
  • 1
    You are missing a semicolon after the button declaration
    – chrisl
    Nov 24 '19 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.
    – Dougie
    Nov 24 '19 at 14:15
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.
    – DeePee
    Nov 24 '19 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.
    – JRobert
    Nov 24 '19 at 14:57
  • @JRobert Thanks :) . U solved my problem.
    – DeePee
    Nov 24 '19 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;
    – bdbdbd
    Nov 24 '19 at 17:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.