void setup() {
pinMode(A3, INPUT);
Serial.begin(9600);
pinMode(3, OUTPUT);
}
void loop() {
int buttonState = analogRead(A3) ;
if (buttonState == 0);
{digitalWrite(3, HIGH);}
else
{digitalWrite(3, LOW);}
if (buttonState == 0);
That semicolon should not be there. It is the only code that is conditionally executed when the test returns true. The next statement will be executed unconditionally
Formatting your code using Auto Format in the IDE shows up the problem
void setup()
{
pinMode(A3, INPUT);
Serial.begin(9600);
pinMode(3, OUTPUT);
}
void loop()
{
int buttonState = analogRead(A3);
if (buttonState == 0)
;
{
digitalWrite(3, HIGH);
}
else
{
digitalWrite(3, LOW);
}
if you close the loop, even better
i still have the same error of "Compilation error: 'else' without a previous 'if'"
What did you intend your code to do?
If you carry out an analogRead, you should expect a returned value between 0 and 1023. Generally it's unlikely to return zero.
it is just an on/off value so it does return to 0
We cannot see what you have changed. Post your updated sketch
That sounds like a digital signal so why not use digitalRead() ?
idk just the way i did it
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.