The Arduino Platform and C Programming (Week 4)
Write a program that allows the user to control the LED connected to pin 13 of the Arduino. When the program is started, the LED should be off. The user should open the serial monitor to communicate with the Arduino. If the user sends the character '1' through the serial monitor then the LED should turn on. If the user sends the character '0' through the serial monitor then the LED should turn off.
If you do not have an Arduino, you can use the web-based Arduino simulator at www.tinkercad.com. You will need to create an account for free. There are instructional videos on that website that will teach you how to use the simulator.
>>>
#define BAUD_RATE 9600 | |
char incomingByte = ' '; | |
void setup(void) | |
{ | |
Serial.begin(BAUD_RATE); | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop(void) | |
{ | |
if(Serial.available() > 0){ | |
incomingByte = Serial.read(); | |
//Serial.println(incomingByte); | |
if(incomingByte == '1'){ | |
digitalWrite(LED_BUILTIN, HIGH); | |
//Serial.println("Led is ON"); | |
} | |
else if(incomingByte == '0'){ | |
digitalWrite(LED_BUILTIN, LOW); | |
//Serial.println("Led is OFF"); | |
} | |
} | |
} |
Comments
Post a Comment