/* * Server 廣播發出訊號,[node][val] * B1 : 當 B node 收到後,會閃 LED 燈 1 次並回傳 1 * B2 : 當 B node 收到後,會閃 LED 燈 2 次並回傳 2 * C1 : 當 C node 收到後,會閃 LED 燈 1 次並回傳 1 */ #include <NewSoftSerial.h> #define node_A_sh 13A200 #define node_A_sl 403D0190 #define node_B_sl 403D018A #define node_C_sl 403D01D0 // set pin 9 as RX uint8_t ssRX = 9; // set pin 10 as TX uint8_t ssTX = 10; // enable soft serial nss NewSoftSerial nss(ssRX, ssTX); int data; int nodeACount=1; int nodeBCount=1; void setup() { Serial.begin(9600); // start soft serial nss.begin(9600); nss.print("A"); nss.print(byte(nodeACount)); nss.print("B"); nss.print(byte(nodeBCount)); } void loop() { if(nss.available()) { data = nss.read(); switch(data) { case 'A': nodeACount++; nodeACount %= 6; Serial.print("nodeACount = "); Serial.println(nodeACount); nss.print("A"); nss.print(byte(nodeACount)); break; case 'B': nodeBCount++; nodeBCount %= 6; Serial.print("nodeBCount = "); Serial.println(nodeBCount); nss.print("B"); nss.print(byte(nodeBCount)); break; } } }
Last modified 15 years ago
Last modified on Mar 5, 2010, 2:37:21 PM