April 2020
Intermediate to advanced
412 pages
9h 58m
English
We will implement a simple program for the Arduino controller that waits for user input on the serial port and turns the built-in LED on or off depending on the data:
void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(9600); while (!Serial);}void loop() { if (Serial.available() > 0) { int inByte = Serial.read(); if (inByte == '1') { Serial.print("Turn LED on\n"); digitalWrite(LED_BUILTIN, HIGH); } else if (inByte == '0') { Serial.print("Turn LED off\n"); digitalWrite(LED_BUILTIN, LOW); } else { Serial.print("Ignore byte "); Serial.print(inByte); Serial.print("\n"); } delay(500); ...Read now
Unlock full access