Part B Background: You may recall that in C++ you can say: cin > x; This causes the entire system to pause, waiting for input. We call this pause a blocking input request (control does not return to the application until the IO is complete). If we wish to emulate blocking input, we can do so by asking the system to wait until bytes of input are available .6] The available) method returns the number of bytes (characters) ready for reading, with 0 (false) as a default if no information is available. Hence, we can block until available with an empty loop block: while (! Serial.available ()) ( The O's indicate that no code is executed while we wait. When the loop's control is broken, information is ready to be read. Introduction: Serial communication (input). 1. For this assignment you will not need to construct any hardware. a. Source: Examples/0.1Basics/Blink.
Explanation / Answer
const int ledPin = 13; // LED pin int n; //Variable to store how many times LED should blink void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); Serial.println("System initialized."); } void loop() { Serial.println("How many times do you wish to have the light blink?"); while(!(Serial.available())) {} n = Serial.parseInt(); for(int i = 0; i