Skip to content

Instantly share code, notes, and snippets.

@SweiLz
Created September 1, 2019 08:29
Show Gist options
  • Save SweiLz/718be39bc0d7b597dfaad7a060ccf10c to your computer and use it in GitHub Desktop.
Save SweiLz/718be39bc0d7b597dfaad7a060ccf10c to your computer and use it in GitHub Desktop.
Arduino Software Serail testcode
#include <SoftwareSerial.h>
SoftwareSerial ss(8, 2); // RX, TX
void setup() {
Serial.begin(115200);
Serial.println("Goodnight moon!");
ss.begin(115200);
ss.println("Hello, world?");
}
unsigned long current_time;
unsigned long timer[2] = {0};
int freq = 1;
#define ECHO 0
#define FREQ 0
void loop() {
#ifdef ECHO
if (ss.available())
{
Serial.write(ss.read());
}
if (Serial.available())
{
ss.write(Serial.read());
}
#endif
#ifdef FREQ
if (ss.available())
{
Serial.write(ss.read());
}
if (Serial.available())
{
freq = Serial.parseInt();
Serial.print("Freq : ");
Serial.println(freq);
}
current_time = millis();
if (current_time - timer[0] > int(1000 / freq))
{
timer[0] = current_time;
char ch = 'a';
ss.write(ch);
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment