bangnaga

Arduino and xbee wireless setup -- Xbee relay code

Jun 16th, 2012 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. //Xbee relay code--arduino and xbee wireless setup
  2.  
  3. int myData = 0;
  4. int const ledpin = 13;
  5.  
  6. void setup(){
  7.     // Start up our serial port, we configured our XBEE devices for 9600 bps.
  8.     Serial.begin(9600);
  9.     pinMode(ledpin, OUTPUT);
  10. }
  11.  
  12. void loop(){
  13.    
  14.     if(Serial.available() > 0){
  15.      
  16.         myData = Serial.read();
  17.      
  18.         if(myData == '1'){
  19.         digitalWrite(ledpin, HIGH);
  20.         Serial.print(myData,BYTE);
  21.         }
  22.      
  23.         if(myData == '2'){
  24.         digitalWrite(ledpin, LOW);
  25.         Serial.print(myData, BYTE);
  26.     }
  27.     else{
  28.     Serial.print(myData, BYTE);
  29.     }
  30.    
  31. }
  32. }
  33.  
  34. //==========================================================
  35. //Code for the AC outlet Project
  36.  
  37. // this is where we will put our data
  38. int myData = 0;
  39. int const ledpin1 = 9;
  40. int const ledpin2 = 11;
  41. void setup(){
  42.     // Start up our serial port, we configured our XBEE devices for 9600 bps.
  43.     Serial.begin(9600);
  44.     pinMode(ledpin1, OUTPUT);
  45.     pinMode(ledpin2, OUTPUT);
  46. }
  47.  
  48. void loop(){
  49.     // handle serial data, if any
  50.     if(Serial.available() > 0){
  51.      
  52.         myData = Serial.read();
  53.      
  54.         if(myData == '1'){
  55.         digitalWrite(ledpin2, LOW);
  56.         delay(100);
  57.         digitalWrite(ledpin1, HIGH);
  58.         delay(100);
  59.         Serial.print(myData,BYTE);
  60.         delay(100);
  61.         }
  62.      
  63.         if(myData == '2'){
  64.         digitalWrite(ledpin1, LOW);
  65.         delay(100);
  66.         digitalWrite(ledpin2, HIGH);
  67.         delay(100);
  68.         Serial.print(myData, BYTE);
  69.         delay(100);
  70.     }
  71.     else{
  72.     Serial.print(myData, BYTE);
  73.     }
  74.    
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment