Pre-Lecture Prep and Pre-Quiz

No pre-quiz for this lecture!

Announcements

Learning Objectives and Outcomes

In this lecture, you will...

By the end of this lecture, you should be able to...

Receiving Inputs from the Serial Terminal

The serial terminal can be used to receive information as well as write it:

// include CircuitPlayground library so we can use CircuitPlayground.
#include <Adafruit_CircuitPlayground.h>

char recChar; // received character

void setup() {
  CircuitPlayground.begin();
  CircuitPlayground.clearPixels();

  Serial.begin(9600);
  while(!Serial);
  
}

void loop (){
  
	// if number of bytes available is greater than zero
	// Serial.available() returns the number of characters
	// received by the Serial terminal
	// while (Serial.available()) is shorthand for:
	// while (Serial.available() > 0)
  while (Serial.available() > 0){

    // save and print received character
		// Serial.read() times out (default is 1s)
		// therefore we usually want to read only when Serial.available() > 0
    recChar = Serial.read(); // puts the character into variable

    Serial.print(recChar);
  }
}

We use a char instead of a byte so that the serial terminal prints out the character code we want, rather than the ASCII value!

http://www.asciitable.com/index/asciifull.gif