Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <RF22.h>
- #include <RF22Router.h>
- #define MY_ADDRESS 5
- #define NODE_ADDRESS_1 12
- #define NODE_ADDRESS_2 13
- #define NODE_ADDRESS_3 14
- RF22Router rf22(MY_ADDRESS);
- int counter = 15;
- int before = 0;
- float start;
- float start_2;
- // LEDs
- int pin1 = 4;
- int pin2 = 5;
- int pin3 = 6;
- int pins[] = {pin1,pin2,pin3};
- void setup() {
- pinMode(pin1, OUTPUT);
- pinMode(pin2, OUTPUT);
- pinMode(pin3, OUTPUT);
- Serial.begin(9600);
- if (!rf22.init())
- Serial.println("RF22 init failed");
- // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
- if (!rf22.setFrequency(431.0))
- Serial.println("setFrequency Fail");
- rf22.setTxPower(RF22_TXPOW_20DBM);
- //1,2,5,8,11,14,17,20 DBM
- rf22.setModemConfig(RF22::GFSK_Rb125Fd125);
- //modulation
- // Manually define the routes for this network
- rf22.addRouteTo(NODE_ADDRESS_1, NODE_ADDRESS_1);
- rf22.addRouteTo(NODE_ADDRESS_2, NODE_ADDRESS_2);
- rf22.addRouteTo(NODE_ADDRESS_3, NODE_ADDRESS_3);
- }
- void loop() {
- uint8_t buf[RF22_ROUTER_MAX_MESSAGE_LEN];
- char incoming[RF22_ROUTER_MAX_MESSAGE_LEN];
- memset(buf, '\0', RF22_ROUTER_MAX_MESSAGE_LEN);
- memset(incoming, '\0', RF22_ROUTER_MAX_MESSAGE_LEN);
- uint8_t len = sizeof(buf);
- uint8_t from;
- int received_value = 0;
- if (rf22.recvfromAck(buf, &len, &from))
- {
- buf[RF22_ROUTER_MAX_MESSAGE_LEN - 1] = '\0';
- memcpy(incoming, buf, RF22_ROUTER_MAX_MESSAGE_LEN);
- //Serial.print("got request from : ");
- //Serial.println(from, DEC);
- received_value = atoi((char*)incoming);
- }
- if(received_value == 0 && before == 0)
- {
- Serial.println("All Quiet");
- }
- else if(received_value == 0 && before != 0 && before != 3)
- {
- if(millis() - start >= 2000)
- {
- digitalWrite(pins[before-1], LOW);
- before = 0;
- }
- }
- else if(before == 3 && received_value == 0)
- {
- if(counter > 0) // if(millis()-start_2 <= 15000)
- {
- Serial.println(counter);
- counter--;
- digitalWrite(pin3, HIGH);
- delay(450);
- digitalWrite(pin3, LOW);
- delay(450);
- }
- }
- else if(received_value != 0)
- {
- start = millis();
- before = received_value;
- switch (before)
- {
- case 1:
- digitalWrite(pin1, HIGH);
- digitalWrite(pin2, LOW);
- digitalWrite(pin3, LOW);
- Serial.println("Level 1 reached! ");
- break;
- case 2:
- digitalWrite(pin1, LOW);
- digitalWrite(pin2, HIGH);
- digitalWrite(pin3, LOW);
- Serial.println("Level 2 reached! ");
- break;
- case 3:
- digitalWrite(pin1, LOW);
- digitalWrite(pin2, LOW);
- digitalWrite(pin3, HIGH);
- Serial.println("Level 3 reached!");
- Serial.println("Password requested. Countdown sequency started:");
- break;
- case 4:
- Serial.println("Password was given correct");
- digitalWrite(pin3, LOW);
- for(int i = 0; i < 110; i++){
- digitalWrite(pin1, HIGH);
- delay(50);
- digitalWrite(pin1, LOW);
- delay(50);
- }
- counter = 15;
- before = 0;
- delay(5000);
- break;
- case 5:
- Serial.println("Password was not given correctly!!! Police on the way");
- digitalWrite(pin3, LOW);
- for(int i = 0; i < 160; i++)
- {
- digitalWrite(pin1, HIGH);
- digitalWrite(pin2, HIGH);
- digitalWrite(pin3, HIGH);
- delay(50);
- digitalWrite(pin1, LOW);
- digitalWrite(pin2, LOW);
- digitalWrite(pin3, LOW);
- delay(50);
- }
- counter = 15;
- before = 0;
- delay(5000);
- break;
- }
- }
- delay(100);
- } //end of void loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement