Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <RF24Network.h>
- #include <RF24.h>
- #include <SPI.h>
- #define btn_red 2
- #define btn_white 3
- #define dip1 9
- #define dip2 10
- #define led1 12
- #define led2 13
- #define channel 90
- #if defined( __AVR_ATtiny84__ )
- const static uint8_t SS = PA7;
- const static uint8_t MOSI = PA6;
- const static uint8_t MISO = PA5;
- const static uint8_t SCK = PA4;
- #endif
- RF24 radio(7,8); //CE,CSN
- RF24Network network(radio);
- const uint16_t base_station = 00;
- const uint16_t judge1 = 01;
- const uint16_t judge2 = 02;
- const uint16_t judge3 = 03;
- const long interval = 500;
- uint16_t node;
- unsigned long btn_send;
- unsigned long previousMillis;
- bool call_wait;
- bool call_confirm;
- bool test_mode;
- void setup() {
- pinMode(dip1, INPUT);
- pinMode(dip2, INPUT);
- pinMode(btn_red, INPUT);
- pinMode(btn_white, INPUT);
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT);
- bool mode_sel1 = digitalRead(dip1);
- bool mode_sel2 = digitalRead(dip2);
- previousMillis = 0;
- //Use the DIP switch to set which judge the remote is assigned to
- if ( (mode_sel1 == LOW) && (mode_sel2 == LOW) ) {
- node = judge1;
- }
- if ( (mode_sel1 == LOW) && (mode_sel2 == HIGH) ) {
- node = judge2;
- }
- if ( (mode_sel1 == HIGH) && (mode_sel2 == HIGH) ) {
- node = judge3;
- }
- if ( (mode_sel1 == HIGH) && (mode_sel2 == HIGH) ) {
- node = judge1;
- }
- //Set up the radio network
- radio.begin();
- network.begin(channel, node);
- radio.setDataRate(RF24_250KBPS);
- radio.setPALevel(RF24_PA_HIGH);
- }
- void loop() {
- radio_comms();
- if (test_mode == true){
- blink_led(led1);
- blink_led(led2);
- if ((digitalRead(btn_red) == LOW) && (digitalRead(btn_white) == HIGH)) {
- btn_send = 1;
- }
- else if ((digitalRead(btn_red) == HIGH) && (digitalRead(btn_white) == LOW)) {
- btn_send = 2;
- }
- else btn_send = 0;
- }
- else {
- if (btn_send == 0) {
- if ((digitalRead(btn_red) == LOW) && (digitalRead(btn_white) == HIGH)) {
- btn_send = 1;
- }
- else if ((digitalRead(btn_red) == HIGH) && (digitalRead(btn_white) == LOW)) {
- btn_send = 2;
- }
- }
- if (call_wait == true) digitalWrite(led1,HIGH);
- else digitalWrite(led1,LOW);
- if (call_confirm == true) {
- digitalWrite(led2, HIGH);
- btn_send = 0;
- }
- else digitalWrite(led2,LOW);
- }
- }
- void radio_comms() {
- network.update();
- //RECEIVING
- while (network.available()){
- RF24NetworkHeader header_rec;
- unsigned long incomingData;
- network.read(header_rec, &incomingData, sizeof(incomingData));
- if(header_rec.from_node == base_station){
- if (incomingData == 1){
- test_mode = false;
- call_wait = true;
- call_confirm = false;
- }
- else if (incomingData == 2){
- test_mode = false;
- call_wait = true;
- call_confirm = true;
- }
- else if (incomingData == 3){
- test_mode = true;
- call_wait = false;
- call_confirm = false;
- }
- else {
- test_mode = false;
- call_wait = false;
- call_confirm = false;
- }
- }
- }
- //SENDING
- RF24NetworkHeader header_snd(judge1);
- bool ok = network.write(header_snd, &btn_send, sizeof(btn_send));
- }
- void blink_led(int ledPin) {
- unsigned long currentMillis = millis();
- int ledState = LOW;
- if (currentMillis - previousMillis >= interval) {
- // save the last time you blinked the LED
- previousMillis = currentMillis;
- // if the LED is off turn it on and vice-versa:
- if (digitalRead(ledPin)== LOW) {
- ledState = HIGH;
- } else {
- ledState = LOW;
- }
- // set the LED with the ledState of the variable:
- digitalWrite(ledPin, ledState);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement