In: Electrical Engineering
Write code using the Arduino IDE that compiles with no errors.
2-bit adder: The code must read two digital input signals and turn on two LEDS as needed to show the sum of the inputs. e.g. 0 + 1 = 01.
Arduino code:-
int b=0;
int a=0;
const int input1 = 2;
const int input2 =3;
const int ledPin1 = 7;
const int ledPin2 = 8;
void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(input1, INPUT);
pinMode(input2, INPUT);
}
void loop() {
b = digitalRead(input2);
a= digitalRead(input1);
if (a==LOW && b== LOW) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
}
else if (a== LOW && b== HIGH) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
}
else if (a== HIGH && b== LOW) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
}
else if (a== HIGH && b== HIGH) {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
}
}
Done compiling without compilation errors: