mcopy/notes/nano_softserial/nano_softserial.ino

31 lines
549 B
Arduino
Raw Normal View History

2023-07-04 02:35:29 +00:00
#include <SoftwareSerial.h>
#define SOFTWARE_RX 10
#define SOFTWARE_TX 11
SoftwareSerial softPort(SOFTWARE_RX, SOFTWARE_TX);
2023-07-04 21:15:26 +00:00
volatile char cmd = 'z';
volatile long now;
volatile long start;
2023-07-04 02:35:29 +00:00
void setup () {
2023-07-04 21:15:26 +00:00
softPort.begin(9600);
start = millis();
pinMode(LED_BUILTIN, OUTPUT);
2023-07-04 02:35:29 +00:00
}
void loop () {
2023-07-04 21:15:26 +00:00
now = millis();
2023-07-04 02:35:29 +00:00
if (softPort.available() > 0) {
2023-07-04 21:15:26 +00:00
cmd = softPort.read();
}
if (cmd == 'x') {
digitalWrite(LED_BUILTIN, HIGH);
}
if (now >= start + 5000) {
softPort.print('x');
2023-07-04 02:35:29 +00:00
}
}