I wanted to make a push button code for two push buttons, but it seems my code is wrong?
If you could please help me, I can't find the problem..
const int ledPin1 = 12; // first LED
const int ledPin2 = 13; // second LED
const int buttonPin1 = 7; // first button connected to LED 1
const int buttonPin2 = 8; // first buttonl connected to LED 2
int buttonState1 = 0; // this is the pushbutton status
int buttonState2 = 0;
void setup ()
{
(ledPin1, OUTPUT); // LED 1 is an output
(ledPin2, OUTPUT); // LED 2 is an output
(buttonPin1 , INPUT); // BUTTON 1 is an input
(buttonPin2 , INPUT); // BUTTON 2 is an input
}
void loop ()
{
buttonState1 = digitalWrite(buttonPin1);
if (buttonState1 == HIGH) // when button 1 is low...
{
digitalWrite (ledPin1, HIGH); // ...LED 1 is low
}
else // ...if button 1 is high...
{
digitalWrite (ledPin1, LOW); // ...LED 1 turns on
}
}
{
buttonState2 = digitalWrite(buttonPin2);
if (buttonState2 == HIGH)
{
digitalWrite (ledPin2, HIGH);
}
else
{
digitalWrite (ledPin2, LOW);
}
}
He was pointing out what was wrong NOT telling you to put that in.
Did you read the error message, it told you there were not enough arguments, that means numbers to pass to the digitalWrite function. It needs two one to say where to write and the other to say what to write.
I'm sorry, can you (super) dumb down for me what this means, and how to solve it? I've seen it before but I don't necessarily know what it means.
Does that mean I wrote something in my code wrong (grammatically) that has to do with the particular function?
This is what I changed it to:
const int ledPin1 = 12; // first LED
const int ledPin2 = 13; // second LED
const int buttonPin1 = 7; // first button connected to LED 1
const int buttonPin2 = 8; // first buttonl connected to LED 2
int buttonState1 = 0; // this is the pushbutton status
int buttonState2 = 0;
void setup ()
{
(ledPin1, OUTPUT); // LED 1 is an output
(ledPin2, OUTPUT); // LED 2 is an output
(buttonPin1 , INPUT); // BUTTON 1 is an input
(buttonPin2 , INPUT); // BUTTON 2 is an input
}
void loop ()
{
buttonState1 = digitalWrite (buttonPin1);
digitalRead;
{
if (buttonState1 == HIGH) // when button 1 is low...
{
digitalWrite (ledPin1, HIGH); // ...LED 1 is low
}
else // ...if button 1 is high...
{
digitalWrite (ledPin1, LOW); // ...LED 1 turns on
}
}
{
buttonState2 digitalWrite (buttonPin2);
digitalRead;
if (buttonState2 == HIGH)
{
digitalWrite (ledPin2, HIGH);
}
else
{
digitalWrite (ledPin2, LOW);
}
}
}
and this is what comes out now, there are less problems but still says "too few arguments"
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Arduino.h: In function 'void loop()':
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Arduino.h:99: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
Button_to_LED_Sketch_ino:21: error: at this point in file
Button_to_LED_Sketch_ino:37: error: expected `;' before 'digitalWrite'
Oh! That was a very simple fix that I'm glad you were able to help me with, sorry for taking so long to understand
And thank you for taking the time to help me with it
Here's the final code I finally got to run properly:
const int ledPin1 = 12; // first LED
const int ledPin2 = 13; // second LED
const int buttonPin1 = 7; // first button connected to LED 1
const int buttonPin2 = 8; // first buttonl connected to LED 2
int buttonState1 = 0; // this is the pushbutton status
int buttonState2 = 0;
void setup ()
{
(ledPin1, OUTPUT); // LED 1 is an output
(ledPin2, OUTPUT); // LED 2 is an output
(buttonPin1 , INPUT); // BUTTON 1 is an input
(buttonPin2 , INPUT); // BUTTON 2 is an input
}
void loop ()
{
buttonState1 = digitalRead (buttonPin1);
if (buttonState1 == HIGH) // when button 1 is low...
{
digitalWrite (ledPin1, HIGH); // ...LED 1 is low
}
else // ...if button 1 is high...
{
digitalWrite (ledPin1, LOW); // ...LED 1 turns on
}
buttonState2 = digitalRead (buttonPin2);
if (buttonState2 == HIGH)
{
digitalWrite (ledPin2, HIGH);
}
else
{
digitalWrite (ledPin2, LOW);
}
}
(ledPin1, OUTPUT); // LED 1 is an output
(ledPin2, OUTPUT); // LED 2 is an output
(buttonPin1 , INPUT); // BUTTON 1 is an input
(buttonPin2 , INPUT); // BUTTON 2 is an input
It shouldn't be running correctly. You're missing some function names there.