im a beginner with arduino and i was wandering if my code looks correct. i am trying to turn on leds by means of buttons.
const int a = 3;
const int b = 4;
const int c = 5; // the number of the pushbutton pin
const int ledpina = 10;
const int ledpinb = 11;
const int ledpinc = 12;
// variables will change:
int buttonStatea = 0;
int buttonStateb = 0;// variable for reading the pushbutton status
int buttonStatec = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledpina, OUTPUT);
pinMode(ledpinb, OUTPUT);
pinMode(ledpinc, OUTPUT);
pinMode(a, INPUT);
pinMode(b, INPUT);
pinMode(c, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonStatea = digitalRead(a);
buttonStateb = digitalRead(b);
buttonStatec = digitalRead(c);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (a == HIGH) {
// turn LED on:
digitalWrite(ledpina, HIGH);
}
if (b == HIGH) {
// turn LED on:
digitalWrite(ledpinb, HIGH);
}
if (c == HIGH) {
// turn LED on:
digitalWrite(ledpinc, HIGH);
}
if (a == LOW) {
// turn LED off:
digitalWrite(ledpina, LOW);
}
if (b == LOW) {
digitalWrite(ledpinb, LOW);
}
if (c == LOW) {
digitalWrite(ledpinc, LOW);
}
}