Hello, i'm with a problem in a code , where it is showing an error , check for me as i can concert it ;
error: expected unqualified-id before 'if'
Code :
int led1 = 10; // Pino do Led
boolean status1 = false; // Verificar Status do led
void setup() {
Serial.begin(9600); //Inicializa a comunicação serial na velocidade 9600
pinMode(led1, OUTPUT); // Define o pino do led como de saida
digitalWrite(led1, LOW); // Inicia o led Desligado
}
void loop() {
char comando = Serial.read();
int chave1 = digitalRead(4);
if (chave1 == HIGH) { // Se a chave for precionada obter valor alto
if (status1) { // Verifica se o led esta ligado ou desligado de acordo com a variável boolean
// executa essa parte se ele estiver ligado
digitalWrite(led1, LOW); // led desligado
status1 = false; // Muda o status para falso para que a proxima vez ele indentifique como desligado
Serial.println("off"); // Envia a string para informar que o led foi desligado
} else {
// executa essa parte se ele estiver desligado
digitalWrite(led1, HIGH); // led ligado
status1 = true; // Muda o status para verdadeiro
Serial.println("on"); //enviar a string para informar que o led foi ligado
}
}
delay(250);
}
if (Serial.read == 'd') { //se a serial receber o caractere d
if (status1) {
digitalWrite(led1, LOW);
status1 = false
Serial.println("off");
}
}
if (Serial.read == 'a') { //se a serial receber o caractere a
if (status1) {
digitalWrite(led1, HIGH);
status1 = true
Serial.println("on");
}
}
Welcome to the Forum. To get the most from this Forum, please read Nick Gammon's "How to" post at the top of the Forum, especially how to use code tags when posting source code here. Also, before your post your code, place the cursor in the source code window of the IDE and press Ctrl-T. This will reformat your code to a common C style. This also makes it easier for us to read. Often, it will catch the kinds of errors pointed out by AWOL.
Also, before your post your code, place the cursor in the source code window of the IDE and press Ctrl-T. This will reformat your code to a common C style.
It will do that if it can. If the number of { is not the same as the number of }, the tool will not reformat anything, but it WILL tell you that there is a problem.
AWOL:
Post your code, but this time use code tags, please.
Here's a spare pair you can have: ``
LED1 int = 10; // Led pin
Status1 boolean = false; // Check LED status
void setup () {
Serial.begin (9600); // Initialize the comunicaç࣠serial speed 9600
pinMode (LED1, OUTPUT); // Set the LED pin as output
digitalWrite (LED1, LOW); // Starts LED Off
}
void loop () {
char command Serial.read = ();
int key1 = digitalRead (4);
if (key1 == HIGH) {// If the key is precionada get high value
if (Status1) {// Check if the led is on or off according to variável boolean
// Run this part if it is connected
digitalWrite (LED1, LOW); // Led off
Status1 = false; // Change to the false status so that the next time he indentifique to off
Serial.println ( "off"); // Send the string to indicate that the LED is off
} Else {
// Run this part if it is off
digitalWrite (LED1, HIGH); // LED connected
Status1 = true; // Change the status to true
Serial.println ( "on"); // Send the string to indicate that the LED was turned on
}
}
delay (250);
}
if (Serial.read == 'd') {// if the serial receive d character
if (Status1) {
digitalWrite (LED1, LOW);
Status1 = false
Serial.println ( "off");
}
}
if (Serial.read == 'a') {// if the serial receive the character to
if (Status1) {
digitalWrite (LED1, HIGH);
Status1 = true
Serial.println ( "on");
}
}
Count your braces. Your loop function ends after the delay(250). The rest of the code is not in a function. That is illegal code and the source of your error.