Ardiuno code question?

Is this correct

// the number of the pushbutton pin

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);

}

else {

// turn LED off:

digitalWrite(ledpina, LOW);

digitalWrite(ledpinb, LOW);

digitalWrite(ledpinc, LOW);

}

}

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 Q2A.ES - All rights reserved.