Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- #define CE_PIN 9
- #define CSN_PIN 10
- uint32_t i = 0;
- const uint64_t pipe = 0xE8E8F0F0E1LL;
- RF24 radio(CE_PIN, CSN_PIN);
- int text[4];
- int button = 7;
- int button2 = 6;
- boolean reading;
- boolean reading2;
- boolean lastButtonStatus = 0;
- boolean lastButtonStatus2 = 0;
- int t=0;
- int b=0;
- void setup() {
- pinMode(button,INPUT);
- pinMode(button2,INPUT);
- radio.begin();
- radio.openWritingPipe(pipe);
- Serial.begin(9600);
- Serial.println("Bat dau");
- }
- void loop() {
- while (reading != lastButtonStatus) {
- lastButtonStatus = reading;
- t=t+1;
- if (t%2==0) {
- Serial.println(" SÚNG SỐ 1 ĐƯỢC LẤY RA");
- text[1]=0;
- }else {
- Serial.println(" SÚNG SỐ 1 ĐƯỢC CẤT VÀO");
- text[1]=1;
- }
- }
- while (Serial.available() > 0)
- {
- delay(5);
- }
- reading = digitalRead(button);
- if (reading==LOW){
- Serial.println("Súng số 1: KHÔNG ");
- text[2]=0;
- }else
- Serial.println("Súng số 1: CÓ ");
- text[2]=1;
- delay(200);
- while (reading2 != lastButtonStatus2) {
- lastButtonStatus2 = reading2;
- b=b+1;
- if (b%2==0) {
- Serial.println(" SÚNG SỐ 2 ĐƯỢC LẤY RA");
- text[3]=0;
- }else {
- Serial.println(" SÚNG SỐ 2 ĐƯỢC CẤT VÀO");
- text[3]=1;
- }
- }
- while (Serial.available() > 0)
- {
- delay(5);
- }
- reading2 = digitalRead(button2);
- if (reading2==LOW){
- Serial.println("Súng số 2: KHÔNG ");
- text[4]=0;
- }
- else {
- Serial.println("Súng số 2: CÓ ");
- text[4]=1;}
- //radio.write( text, sizeof(text));
- delay(200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement