Skip to content

Instantly share code, notes, and snippets.

@Apihplays
Last active April 6, 2019 06:52
Show Gist options
  • Save Apihplays/dc3a8a1062b3228b95e8e5b039d10108 to your computer and use it in GitHub Desktop.
Save Apihplays/dc3a8a1062b3228b95e8e5b039d10108 to your computer and use it in GitHub Desktop.
testing data sending using mega to nodemcu
//connect the rx<-0/tx->0 on nodemcu rx/tx after mega and nodemcu done uploading this code.
/*-----------------for mega------------------------*/
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.write("0");
delay(500);
Serial.write("1");
delay(500);
}
/*---------------------for nodemcu-------------*/
#define LED D4
void setup() {
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
Serial.begin(115200);
Serial.println("Blinking on GPIO pin " + String(LED));
}
void loop() {
if (Serial.available()) {
char s = Serial.read();
if (s == '1') {
digitalWrite(LED, HIGH);
Serial.println("on");
}
if (s == '0') {
digitalWrite(LED, LOW);
Serial.println("off");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment