int buttonPin= 7; //the number of the pushbutton pinPreformatted text
int buttonState=0; //variable for reading the pushbutton statusPreformatted text
int ledPin=12;
int ledState=0; //variable for reading the LED statusPreformatted text
void setup() Preformatted text
{ Preformatted text
pinMode(12, OUTPUT); // initialise the ledPin as an output: Preformatted text
pinMode(buttonPin, INPUT); // initialise the buttonPin as an input: Preformatted text
} Preformatted text
void loop() Preformatted text
{ Preformatted text
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value: Preformatted text
ledState = digitalRead(ledPin); //read the state of the LED valuePreformatted text
if (buttonState == LOW), (12State == LOW); // if the pushbutton and LED is on.Preformatted text
{Preformatted text
digitalWrite(); // do nothing if the buttonState is off and 12State is off: Preformatted text
} Preformatted text
if (buttonState ==HIGH), (12State == HIGH); // if buttonState is on and 12State is onPreformatted text
{ Preformatted text
digitalWrite(12, LOW); // turn LED off if the buttonState is on and 12State is on: Preformatted text
} Preformatted text
if (buttonState == LOW), (12State == HIGH); // if buttonState is off and 12State is onPreformatted text
{Preformatted text
digitalWrite();Preformatted text
}Preformatted text
if (buttonState == HIGH), (12State == LOW); // if buttonState is on and 12State is offPreformatted text
{digitalWrite(12, HIGH); //turn LED on if buttonState is on and LED is offPreformatted text
}Preformatted text
That's the 4th last by my count, but whatever, the one I pointed out is wrong anyway.
But try this for the one you want fixing:
if (buttonState == HIGH && 12State == LOW);
BUT also lose the ; on the end, since that's a premature ending of the "if". Then put the lines you want to run when the "if" is passed, in a pair of {}.
Can you fix the formatting of the code in original post.... What's all that "preformatted text" stuff? Very difficult to read. Code should look thus:
Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
int buttonPin= 7; //the number of the pushbutton pin
int buttonState=0; //variable for reading the pushbutton status
int ledPin=12;
int ledState=0; //variable for reading the LED status
void setup()
{
pinMode(12, OUTPUT); // initialise the ledPin as an output:
pinMode(buttonPin, INPUT); // initialise the buttonPin as an input:
}
void loop()
{
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value:
ledState = digitalRead(ledPin); //read the state of the LED value
if (buttonState == LOW && 12State == LOW); // if the pushbutton and LED is on.
{
digitalWrite(); // do nothing if the buttonState is off and 12State is off:
}
if (buttonState ==HIGH && 12State == HIGH); // if buttonState is on and 12State is on
{
digitalWrite(12, LOW); // turn LED off if the buttonState is on and 12State is on:
}
if (buttonState == LOW && 12State == HIGH); // if buttonState is off and 12State is on
{
digitalWrite();
}
if (buttonState == HIGH && 12State == LOW); // if buttonState is on and 12State is off
{
digitalWrite(12, HIGH) //turn LED on if buttonState is on and LED is off
};
}
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"
C:\Users\Documents\Arduino\sketch_sketch_.ino: In function 'void loop()':
sketch_20:27: error: unable to find numeric literal operator 'operator""State'
if (buttonState == LOW && 12State == LOW); // if the pushbutton and LED is on.
^~~~~~~
sketch_22:16: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite(); // do nothing if the buttonState is off and 12State is off:
^
In file included from sketch\sketch_.ino.cpp:1:0:
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:135:6: note: declared here
void digitalWrite(uint8_t pin, uint8_t val);
^~~~~~~~~~~~
sketch_:25:28: error: unable to find numeric literal operator 'operator""State'
if (buttonState ==HIGH && 12State == HIGH); // if buttonState is on and 12State is on
^~~~~~~
sketch_:29:27: error: unable to find numeric literal operator 'operator""State'
if (buttonState == LOW && 12State == HIGH); // if buttonState is off and 12State is on
^~~~~~~
sketch:31:18: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite();
^
In file included from sketch\sketch_.ino.cpp:1:0:
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:135:6: note: declared here
void digitalWrite(uint8_t pin, uint8_t val);
^~~~~~~~~~~~
sketch_:33:28: error: unable to find numeric literal operator 'operator""State'
if (buttonState == HIGH && 12State == LOW); // if buttonState is on and 12State is off
^~~~~~~
sketch_:36:3: error: expected ';' before '}' token
};
^
exit status 1
unable to find numeric literal operator 'operator""State'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
You still have all those ";" on the end of the "if"s so even if the test passes, what follows doesn't run.
And sorry I misled you: you only have to use {} if there's more than one line to run if the test passes. It's ok to have only one line in the {} though, like you have it now, and I often do that as a matter of course. Just a bit of extra typing, but if you then edit the code and add another line, the {} are already there and won't get forgotten.
But they didn't try to declare that anyway. I think it should be ledState, which is declared? Something's hinky with some cutting and pasting, methinks.
(Anyway I'm off for my morning run and then some breakfast....)
Thanks! So if I want nothing to happen, what do I put in the empty brackets... Or do I just delete the line? (I was away in class so I have no idea what to do...)
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"
C:\Users\Documents\Arduino\sketch_may24a\sketch_may24a.ino: In function 'void loop()':
sketch_may24a:22:16: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite(); // do nothing if the buttonState is off and 12State is off:
^
In file included from sketch\sketch_may24a.ino.cpp:1:0:
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:135:6: note: declared here
void digitalWrite(uint8_t pin, uint8_t val);
^~~~~~~~~~~~
sketch_may24a:31:18: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite();
^
In file included from sketch\sketch_may24a.ino.cpp:1:0:
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:135:6: note: declared here
void digitalWrite(uint8_t pin, uint8_t val);
^~~~~~~~~~~~
sketch_may24a:36:3: error: expected ';' before '}' token
};
^
exit status 1
too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
int buttonPin= 7; //the number of the pushbutton pin
int buttonState=0; //variable for reading the pushbutton status
int ledPin=12;
int ledState=0; //variable for reading the LED status
void setup()
{
pinMode(12, OUTPUT); // initialise the ledPin as an output:
pinMode(buttonPin, INPUT); // initialise the buttonPin as an input:
}
void loop()
{
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value:
ledState = digitalRead(ledPin); //read the state of the LED value
if (buttonState == LOW &&ledState == LOW) // if the pushbutton and LED is on.
{
digitalWrite(); // do nothing if the buttonState is off and 12State is off:
}
if (buttonState ==HIGH && ledState == HIGH) // if buttonState is on and 12State is on
{
digitalWrite(12, LOW); // turn LED off if the buttonState is on and 12State is on:
}
if (buttonState == LOW && ledState == HIGH) // if buttonState is off and 12State is on
{
digitalWrite();
}
if (buttonState == HIGH && ledState == LOW) // if buttonState is on and 12State is off
{
digitalWrite(12, HIGH) //turn LED on if buttonState is on and LED is off
};
}
No, those are holders for the parts that are present in the digitalWrites that work. But generally if you don't want to do something, don't do anything. So leave that whole thing out.
That's a huge pity and I feel for you, whatever the reason for your absence was, but it's not going to work by you just throwing random stuff at the compiler and trying to fix it when it screams at you line by line.