Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

1. Encoding Switches a. The name of this program will be lab5pl b. As described in Lab 4, the EduShield comes with a four pushbutton switches SWO on pin 12, SW1 on pin 8, SW2 on pin 7, and SW3 on pin 4 These switches pull the pins low when they are pressed and thus they are "active- low." The Arduino switch inputs must be configured to have a 20 kS2 pull-up resistor on input pin using the command: pinMode (pin, INPUT_PULLUP) c. d. To read a digital input signal, we use the function digitalRead (pin); The returned value from digitalRead) is either HIGH (1) or LOW (0) e. Write the function proto-type read switches () that has no input parameter and has as output a single integer that is a binary encoding of the four switches. f. Inside this function, read all four switches and then sum them with binary weighting, such that SWO is the LSB (with a weight of 20) and SW3s the MSB (with a weight of 2). To make the switches "active-high" invert the value of each reading before applying the binary weight. As such, "no switches pressed" will be encoded as 0, whereas all four switches will be the highest binary value g. Write a program that calls function read_switches() and displays the result in decimal and binary format (in columns). Put a delay of 1 second between each reading. Include a suitable header row for the two columns Run the program. Show the results to the TAEach student upload the source file to Canvas

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
  
}
}