Error compiling for board Arduino/Genuino Uno.

When I compile this code, it gives me this error: Error compiling for board Arduino/Genuino Uno.

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

 tone(A5,200); 
 delay(1000);  

 tone(A5,225);  
 delay(400);    
 
 tone(A5,240);    
 delay(550);
 
 tone(A5,200);
 delay(700);

 tone(A5,293);
 delay(225);
 
 tone(A5,285); 
 delay(225);

 tone(A5,285); 
 delay(225);
 
 tone(A5,285); 
 delay(225);
 
 tone(A5,285); 
 delay(225);
 
 tone(A5,285); 
 delay(225);
   
}

No, it gives you much more than that. You need to scroll the black console window at the bottom of the Arduino IDE window up and look at the real error message!

Every Arduino sketch must have a setup() and a loop() function, even if they're left empty. Your sketch is missing a loop function, thus the error.

Ohhhh! I was trying to add a for loop and gave up! So I deleted it! Thanks.

You’re welcome. I’m glad if I was able to be of assistance. Enjoy!
Per

I'm guessing the linker failed because 'loop()' is not declared anywhere.

Bonsoir,
Mon projet consiste à peser sur un bouton et faire fonctionner le servo pour qu’il se rende à un certain angle. Une fois rendu à cet angle, une lumière s’Allumera. Le seul souci est cette erreur de compilation que je reçois lors de la vérification du code. J’ai réinstallé le logiciel et vérifié si j’avais le bon type de carte et programmeur, mais sans succès.

Voici le code :

#include <Servo.h>

Servo servo1;

int pos = 0; // initial position
int button1 = 4; // set the first button to pin 4
int button2 = 2; // set the second button to pin 2
int redLed = 10; // se the red Led to pin 10
int greenLed = 13; // set the green Led to pin 13

void setup()
{
servo1.attach(1); // set the servo to pin 1
pinMode (greenLed, OUTPUT); // declaring the green Led as an output
pinMode (redLed, OUTPUT); // declaring the redLed as an output
}

void loop(){
if(pinMode(button1,INPUT)==HIGH && pinMode(button2,INPUT)==LOW){
servo1.write(180); // go to 180 degrees
delay (15); // wait for the servo to move
digitalWrite (greenLed, HIGH); // set brightness to the green Led
digitalWrite (redLed, LOW); // set no brightness to the red Led
}

if(pinMode (button1,INPUT)==LOW && pinMode(button2,INPUT)==HIGH){

servo1.write(0); // go to 0 degree
delay(15); // wait for the servo to move
digitalWrite(greenLed, LOW); // set no brightness to the green Led
digitalWrite (redLed, HIGH); // set brightness to the red Led
}
}

Voici le message d’erreur :

Arduino:1.8.8 (Windows Store 1.8.19.0) (Windows 10), Carte : “Arduino/Genuino Uno”

In file included from sketch\internet_2_buttons_servo_modif_3.ino.cpp:1:0:

C:\Users\admin\Documents\Arduino\internet_2_buttons_servo_modif_2\internet_2_buttons_servo_modif_3\internet_2_buttons_servo_modif_3.ino: In function ‘void loop()’:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: invalid operands of types ‘void’ and ‘int’ to binary ‘operator==’

#define HIGH 0x1

^

C:\Users\admin\Documents\Arduino\internet_2_buttons_servo_modif_2\internet_2_buttons_servo_modif_3\internet_2_buttons_servo_modif_3.ino:20:28: note: in expansion of macro ‘HIGH’

if(pinMode(button1,INPUT)==HIGH && pinMode(button2,INPUT)==LOW){

^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:41:14: error: invalid operands of types ‘void’ and ‘int’ to binary ‘operator==’

#define LOW 0x0

^

C:\Users\admin\Documents\Arduino\internet_2_buttons_servo_modif_2\internet_2_buttons_servo_modif_3\internet_2_buttons_servo_modif_3.ino:20:60: note: in expansion of macro ‘LOW’

if(pinMode(button1,INPUT)==HIGH && pinMode(button2,INPUT)==LOW){

^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:41:14: error: invalid operands of types ‘void’ and ‘int’ to binary ‘operator==’

#define LOW 0x0

^

C:\Users\admin\Documents\Arduino\internet_2_buttons_servo_modif_2\internet_2_buttons_servo_modif_3\internet_2_buttons_servo_modif_3.ino:27:31: note: in expansion of macro ‘LOW’

if(pinMode (button1,INPUT)==LOW && pinMode(button2,INPUT)==HIGH){

^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: invalid operands of types ‘void’ and ‘int’ to binary ‘operator==’

#define HIGH 0x1

^

C:\Users\admin\Documents\Arduino\internet_2_buttons_servo_modif_2\internet_2_buttons_servo_modif_3\internet_2_buttons_servo_modif_3.ino:27:62: note: in expansion of macro ‘HIGH’

if(pinMode (button1,INPUT)==LOW && pinMode(button2,INPUT)==HIGH){

^

exit status 1
Erreur de compilation pour la carte Arduino/Genuino Uno

Ce rapport pourrait être plus détaillé avec
l’option “Afficher les résultats détaillés de la compilation”
activée dans Fichier → Préférences.

Je ne comprends tout simplement pas quoi faire pour avancer dans mon code.
Merci d’avance.

arduinoprogrammation2k19:
Bonsoir

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar, then you can just manually add the code tags:

[code]

[color=blue]// your code is here[/color]

[/code]

Using code tags and other important information is explained in the How to use this forum post. Please read it.

This part of the forum is for English language. Are you aware there is a “Français” language section of the forum?

arduinoprogrammation2k19:
if(pinMode(button1,INPUT)==HIGH && pinMode(button2,INPUT)==LOW){

Spend some time studying this:
https://www.arduino.cc/reference/en/language/functions/digital-io/pinmode/

if(pinMode(button1,INPUT)==HIGH && pinMode(button2,INPUT)==LOW){

pinMode(pin, mode) does not return a value so you can't compare the value returned against HIGH or LOW.

I think you probably meant to write:

if(digitalRead(button1)==HIGH && digitalRead(button2)==LOW){