Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1.  
  2. #include <SPI.h>
  3. #include <nRF24L01.h>
  4. #include <RF24.h>
  5. #define CE_PIN 9
  6. #define CSN_PIN 10
  7.  
  8. uint32_t i = 0;
  9. const uint64_t pipe = 0xE8E8F0F0E1LL;
  10.  
  11.  
  12. RF24 radio(CE_PIN, CSN_PIN);
  13. int text[4];
  14.  
  15. int button = 7;
  16. int button2 = 6;
  17. boolean reading;
  18. boolean reading2;
  19. boolean lastButtonStatus = 0;
  20. boolean lastButtonStatus2 = 0;
  21. int t=0;
  22. int b=0;
  23.  
  24. void setup() {
  25. pinMode(button,INPUT);
  26. pinMode(button2,INPUT);
  27. radio.begin();
  28. radio.openWritingPipe(pipe);
  29. Serial.begin(9600);
  30. Serial.println("Bat dau");
  31. }
  32.  
  33. void loop() {
  34.  
  35.  
  36. while (reading != lastButtonStatus) {
  37.  
  38. lastButtonStatus = reading;
  39.  
  40. t=t+1;
  41. if (t%2==0) {
  42. Serial.println(" SÚNG SỐ 1 ĐƯỢC LẤY RA");
  43. text[1]=0;
  44. }else {
  45. Serial.println(" SÚNG SỐ 1 ĐƯỢC CẤT VÀO");
  46. text[1]=1;
  47. }
  48. }
  49.  
  50.  
  51.  
  52. while (Serial.available() > 0)
  53. {
  54.  
  55.  
  56. delay(5);
  57. }
  58.  
  59. reading = digitalRead(button);
  60. if (reading==LOW){
  61.  
  62. Serial.println("Súng số 1: KHÔNG ");
  63. text[2]=0;
  64. }else
  65. Serial.println("Súng số 1: CÓ ");
  66. text[2]=1;
  67. delay(200);
  68.  
  69.  
  70. while (reading2 != lastButtonStatus2) {
  71.  
  72. lastButtonStatus2 = reading2;
  73.  
  74. b=b+1;
  75. if (b%2==0) {
  76. Serial.println(" SÚNG SỐ 2 ĐƯỢC LẤY RA");
  77. text[3]=0;
  78. }else {
  79. Serial.println(" SÚNG SỐ 2 ĐƯỢC CẤT VÀO");
  80. text[3]=1;
  81. }
  82. }
  83.  
  84.  
  85.  
  86. while (Serial.available() > 0)
  87. {
  88.  
  89.  
  90. delay(5);
  91. }
  92.  
  93. reading2 = digitalRead(button2);
  94. if (reading2==LOW){
  95.  
  96. Serial.println("Súng số 2: KHÔNG ");
  97. text[4]=0;
  98. }
  99. else {
  100. Serial.println("Súng số 2: CÓ ");
  101. text[4]=1;}
  102. //radio.write( text, sizeof(text));
  103. delay(200);
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement