We wanted our LED to turn on if we sent an 'a' to the Arduino. To read or write a letter to a variable, we will put the letter in single quotation marks. While still being inside the main if statement ( 0)>) we add if statements. In total, this line read: inByte = Serial.read() we will use 'Serial.read()', which will read the byte. Inside that if statement, we need to read the byte and store it for later use. So, if we use 'if(Serial.available() > 0)', we know there is at least one byte that we can read. So, we use 'Serial.available()' This function returns the number of bytes that are available to be read. In the void loop we first need to know when a byte is available to be read. We used 9600bits per second, so we added - Serial.begin(9600) In the void setup, set pin 13 as an output and use 'Serial.begin() ' to initiate the serial communication. Then connect your USB cable.Ĭreate an integer to store the incoming serial byte. Serial communications can be used in many ways, but in this situation we will use it to turn off and on an LED.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |