i have to follow to prompt to make the code required above. it needs to be in c
ID: 3754731 • Letter: I
Question
i have to follow to prompt to make the code required above.
it needs to be in c and work with the arduino
Explanation / Answer
This can be done using C language for Edushield Arduino board
int a = 4; //Input pins
int b = 7;
int c = 8;
int d = 12;
int sw0,sw1,sw2,sw3; //switch data type to read input
int LED1 = 2; ////LED in edushield which gives output according to input
int LED2 = 3;
int LED3 = 5;
int LED4 = 6;
void setup()
{
pinMode(a,INPUT_PULLUP);
pinMode(b,INPUT);
pinMode(c,INPUT);
pinMode(d,INPUT);;
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
}
void read_switch() {
// put your main code here, to run repeatedly:
sw0 = digitalRead(b);
sw1 = digitalRead(c);
sw2 = digitalRead(d);
sw3 = digitalRead(e);
if(sw3==LOW && sw2==LOW && sw1==HIGH && sw0==LOW)
{
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW);
}
if(sw3==LOW && sw2==HIGH && sw1==LOW && sw0==LOW)
{
digitalWrite(LED1,LOW);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
}
if(sw3==HIGH && sw2==LOW && sw1==LOW && sw0==LOW)
{
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
}
if(sw3==LOW && sw2==HIGH && sw1==LOW && sw0==HIGH)
{
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH); // read the switch input
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.