library Button.h help. IF/else doesnt work

Hello! im really new on this. i cant get this done. can anyone help me?

Attaching a .jpeg

You need to learn how to program in C, ... get a c or c++ tutorial

if (condition) {
} else {

( Copying an image of your code is not a best practice... please read the posts at the top of the forum on how to post questions)

#include <Button.h>

int diod=13;

Button ledOn(4);

void setup() {
pinMode(13, OUTPUT);



void loop() {
if (ledOn.pressed())
digitalWrite(diod, HIGH);
digitalWrite(diod, LOW);


i get this

error: 'else' without a previous 'if'



exit status 1
'else' without a previous 'if'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

You need two sets of curly brackets but it is hard to explain where in a photograph.

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    editing your post. Do not change your existing posts in any other way.
    You may make additional posts as needed.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!

Have you read #1?? I gave you the correct syntax for an if else including many statements. you need to use {}.

Fix that and fix your code posts above by adding the code Tags. Your code should look like this

// your code here