本站改版新增arduino频道
arduino ASRPRO 串口通讯范例
#includeSoftwareSerial mySerial(10, 11); // RX, TX String value; #define LED_PIN 13 #define RELAY_PIN 12 void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } mySerial.begin(9600); pinMode(LED_PIN, OUTPUT); pinMode(RELAY_PIN, OUTPUT); } void loop() { // run over and over if (mySerial.available()) { value = (mySerial.readString()); Serial.println(value); if (value == "LED ON") { digitalWrite(LED_PIN,HIGH); } else if (value == "LED OFF") { digitalWrite(LED_PIN,LOW); } else if (value == "RELAY ON") { digitalWrite(RELAY_PIN,HIGH); } else if (value == "RELAY OFF") { digitalWrite(RELAY_PIN,LOW); } } }
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0093770027160645 seconds