Created
August 12, 2021 00:14
-
-
Save AlienKevin/6a34fabbc08b8017301b1d76403e72ce to your computer and use it in GitHub Desktop.
arduino-nano-33-ble-uart/receiver.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(LED_BUILTIN, OUTPUT); // set LED pin as output | |
digitalWrite(LED_BUILTIN, LOW); // switch off LED pin | |
Serial1.begin(9600); // initialize UART with baud rate of 96006 | |
} | |
void loop() | |
{ | |
while (Serial1.available() >= 0) | |
{ | |
char receivedData = Serial1.read(); // read one byte from serial buffer and save to receivedData | |
if (receivedData == '1') | |
{ | |
digitalWrite(LED_BUILTIN, HIGH); // switch LED On | |
Serial.println("LEDS ON"); | |
} | |
else if (receivedData == '0') | |
{ | |
digitalWrite(LED_BUILTIN, LOW); // switch LED Off | |
Serial.println("LEDS OFF"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment