I don't understand this message telling me 'else without a previous if'.
This is my code :
if(PRV < 145)
{
digitalWrite(Y1, HIGH);
}
else
{
digitalWrite(Y1, LOW);
}
delay(100);
I don't understand this message telling me 'else without a previous if'.
This is my code :
if(PRV < 145)
{
digitalWrite(Y1, HIGH);
}
else
{
digitalWrite(Y1, LOW);
}
delay(100);
Please post the complete real program that causes the error using code tags when you do
Probably caused by a stray semicolon.
if (x < y); // malplaced ;
{
yes();
}
else
{
no();
}
const int Y1 = 7;
const int Y2 = 6;
const int Y3 = 5;
const int R1 = 4;
const int R2 = 3;
const int R3 = 2;
const int PR1 = A1;
int PRV = 0;
void setup() {
Serial.begin(9600);
pinMode(Y1, OUTPUT);
pinMode(Y2, OUTPUT);
pinMode(Y3, OUTPUT);
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
pinMode(R3, OUTPUT);
pinMode(PR1, INPUT);
int PRV = 0;
}
void loop()
{
PRV = analogRead(PR1);
Serial.print(analogRead(PR1));
Serial.print("\t");
Serial.println();
if(PRV < 145)
{
digitalWrite(Y1, HIGH);
}
else
{
digitalWrite(Y1, LOW);
}
delay(100);
Is this better?
There is missing a final } to end "void loop()", you are redeclaring "PRV" in setup() for no reason and you are calling analogRead twice on loop() - once is enough. But there are no apparent reason for the error you get.