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

5. Here is a flow chart of some algorithm. Please write an Arduino code which wi

ID: 3905148 • Letter: 5

Question

5. Here is a flow chart of some algorithm. Please write an Arduino code which will accomplish the same. (5 points) You'll have to define your own variables even though that "slight detail" is not included in the flowchart. Also, please write down why the stop box in this code is not connected (Test out your code in Tinker cad to see if it actually works, before submitting the assignment) Start Set pin 7, 8 as outputs this is where LEDs are connected) Set pin 9 as input this is where a button is connected Begin serial communication Read the voltage at pin 9 Heo is valtage HIGH Yes Serial print "button is Turn the red led on pin-8 ON Turn the green led on pin-7 OFF Turn the green led an pin-7 ON Turn the red led on pin-B OFF Stop

Explanation / Answer

Please find the required code in Arduino 1.8.5:

//================================================

int btstate=0;
void setup() {
// Setting pin 7 and 8 as OUTPUT and 9 as INPUT
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,INPUT);
// Beginning serial communication
Serial.begin(9600);
}

void loop() {
btstate=digitalRead(9); // Reading the voltage at pin 9
if(btstate==HIGH) // If button is pressed, the input from 9 will be HIGH
{
Serial.println("Button Pressed");
digitalWrite(7,HIGH); // Turning green LED @ 7 ON
digitalWrite(8,LOW); // Turning red LED @ 8 OFF
}
else // If button is not pressed, the input from 9 will be LOW
{
digitalWrite(8,HIGH); // Turning red LED @ 8 ON
digitalWrite(7,LOW); // Turning green LED @ 7 OFF
}
}

//================================================

The reason for stop box not being connected is that, once the program is written in the arduino's microprocessor, it keeps on looping. This one case see as there are two functions in any arduino sketch setup() and loop(). setup keeps all the initializations while loop contains all the executions.

Hope this helps! If it works, please thumbs up!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote