p25_WirelessRemoteControlKit.ino 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Demo code for Project 25 - Wireless Remote Control Kit
  3. Detect the state of D7-D11 and display the information on Serial Monitor
  4. http://makerstudio.cc
  5. */
  6. // constants won't change. They're used here to
  7. // set pin numbers:
  8. const int Pin0 = 7;
  9. const int Pin1 = 8;
  10. const int Pin2 = 9;
  11. const int Pin3 = 10;
  12. const int Pin4 = 11;
  13. //set low state ;
  14. int State0 = LOW;
  15. int State1 = LOW;
  16. int State2 = LOW;
  17. int State3 = LOW;
  18. int State4 = LOW;
  19. void setup() {
  20. // initialize the Recever pins as input:
  21. pinMode(Pin0, INPUT);
  22. pinMode(Pin1, INPUT);
  23. pinMode(Pin2, INPUT);
  24. pinMode(Pin3, INPUT);
  25. pinMode(Pin4, INPUT);
  26. Serial.begin(9600);
  27. }
  28. void loop(){
  29. // read the state of the pushbutton value:
  30. State0 = digitalRead(Pin0);
  31. State1 = digitalRead(Pin1);
  32. State2 = digitalRead(Pin2);
  33. State3 = digitalRead(Pin3);
  34. State4 = digitalRead(Pin4);
  35. if(State4)//State4 act as the flag of received message.
  36. //it equals 1 when received message,else equals 0.
  37. {
  38. //print matched flag of the received message;
  39. if(State0){Serial.println("received data:B");}
  40. if(State1){Serial.println("received data:D");}
  41. if(State2){Serial.println("received data:A");}
  42. if(State3){Serial.println("received data:C");}
  43. }
  44. else
  45. {
  46. //no message received.
  47. }
  48. delay(100);
  49. }