Changes between Version 1 and Version 2 of wade/embedded/arduino/example/example_8_1_Xbee_Server_broadcast


Ignore:
Timestamp:
Mar 5, 2010, 3:14:24 PM (14 years ago)
Author:
wade
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • wade/embedded/arduino/example/example_8_1_Xbee_Server_broadcast

    v1 v2  
    22{{{
    33#!c
     4/*
     5 * Server 廣播發出訊號,[node][val]
     6 * B1 : 當 B node 收到後,會閃 LED 燈 1 次並回傳 1
     7 * B2 : 當 B node 收到後,會閃 LED 燈 2 次並回傳 2
     8 * C1 : 當 C node 收到後,會閃 LED 燈 1 次並回傳 1
     9 * 當 Server 收到 node A 或 node B 回應後,再指定下個工作予其執行。
     10 */
     11#include <NewSoftSerial.h>
     12#define node_A_sh 13A200
     13#define node_A_sl 403D0190
     14#define node_B_sl 403D018A
     15#define node_C_sl 403D01D0
     16
     17// set pin 9 as RX
     18uint8_t ssRX = 9;
     19// set pin 10 as TX
     20uint8_t ssTX = 10;
     21// enable soft serial nss
     22NewSoftSerial nss(ssRX, ssTX);
     23
     24int data;
     25int nodeACount=1;
     26int nodeBCount=1;
     27
     28void setup()
     29{
     30  Serial.begin(9600);
     31  // start soft serial
     32  nss.begin(9600);
     33  nss.print("A");
     34  nss.print(byte(nodeACount));
     35  nss.print("B");
     36  nss.print(byte(nodeBCount));
     37}
     38
     39
     40void loop()
     41{
     42  if(nss.available())
     43  {
     44    data = nss.read();
     45    switch(data)
     46    {
     47      case 'A':
     48        nodeACount++;
     49        nodeACount %= 6;
     50        Serial.print("nodeACount = ");
     51        Serial.println(nodeACount);
     52        nss.print("A");
     53        nss.print(byte(nodeACount));
     54        break;
     55      case 'B':
     56        nodeBCount++;
     57        nodeBCount %= 6;
     58        Serial.print("nodeBCount = ");
     59        Serial.println(nodeBCount);
     60        nss.print("B");
     61        nss.print(byte(nodeBCount));
     62        break;
     63    }
     64  }
     65}
     66
     67}}}
     68