The flow chart of the algorithm has start bubble then drop down arrow to a recta
ID: 2293858 • Letter: T
Question
The flow chart of the algorithm has start bubble then drop down arrow to a rectangle which reads "set pin 7, 8 as outputs (this is where the LED's are connected) drop down arrow to another rectangle that reads set pin 9 as input (this is where the button is connected) drop down arrow to rectangle that reads begin serial communication drop down arrow to rectangle that reads read the voltage at pin 9 drop down arrow to a diamond shape that reads is voltage HIGH this diamond shape has 2 arrows coming out of it one on the left and one on the right. The one of the left reads NO pointing to a rectangle box that reads turn the red LED on pin 8 ON with a drop down arrow to a rectangle box that reads turn the green LED on pin 7 OFF. Going to back to the diamond shape to the right arrow that reads YES to another diamond shape that reads serial print "button is pressed" with a drop down arrow to a rectangle box that reads turn the green LED on pin 7 ON with a drop down arrow to another rectangle box that reads turn the red LED on pin 8 OFF. From both 2 different rectangle boxes (the first that reads turn the green LED on pin 7 OFF and the second one that reads turn the turn the red LED on pin 8 OFF) from both those boxes they each have their own drop down arrows that lead to an arrow going from left to right, back up again and shooting back over to the middle (almost making a complete square) hitting the arrow between the boxes the read (going from top to bottom) Begin serial communication and read the voltage at pin 9
Explanation / Answer
int inPin = 9;
int val = 0;
void setup() {
//Put your setup code here, to run once:
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, INPUT);
}
void loop() {
//Put your main code here, to run repeatedly:
Serial.begin(9600);
val = digitalRead(inPin);
if(val == HIGH)
{
Serial.println("Button is pressed");
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
}
else
{
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
}
}