Skip to content

Instantly share code, notes, and snippets.

@AlienKevin
Created August 12, 2021 00:14
Show Gist options
  • Save AlienKevin/6a34fabbc08b8017301b1d76403e72ce to your computer and use it in GitHub Desktop.
Save AlienKevin/6a34fabbc08b8017301b1d76403e72ce to your computer and use it in GitHub Desktop.
arduino-nano-33-ble-uart/receiver.cpp
#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