Changes between Initial Version and Version 1 of wade/embedded/arduino/example/example_8_Xbee_Xbee_ATcommand


Ignore:
Timestamp:
Mar 5, 2010, 2:15:38 PM (14 years ago)
Author:
wade
Comment:

--

Legend:

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

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