add NRFtoTallylight
parent
322c201fcc
commit
604bf9cbb4
@ -0,0 +1,73 @@
|
||||
#include <RF24.h>
|
||||
#include <nRF24L01.h>
|
||||
|
||||
//tally LEDs
|
||||
const int tallyLED[] = {2,3};
|
||||
const int tallyLEDlength = 2;
|
||||
boolean tallyLEDstat[2];
|
||||
|
||||
# define errorLED 4
|
||||
|
||||
//init NRF
|
||||
RF24 radio (7, 8);
|
||||
const uint16_t address = 0xADB5;
|
||||
uint16_t datareceive;
|
||||
|
||||
//define min interval to show error
|
||||
unsigned long currentTime = millis();
|
||||
unsigned long previousTime = 0;
|
||||
const long errorTime = 3000;
|
||||
|
||||
void setup(){
|
||||
for (int i=0; i < tallyLEDlength; i++){
|
||||
pinMode(tallyLED[i], OUTPUT);
|
||||
digitalWrite(tallyLED[i], LOW);
|
||||
}
|
||||
pinMode(errorLED, OUTPUT);
|
||||
digitalWrite(errorLED, HIGH);
|
||||
|
||||
//start Serial
|
||||
Serial.begin(9600);
|
||||
|
||||
//start NRF
|
||||
radio.begin();
|
||||
radio.openReadingPipe(0, address);
|
||||
radio.setPALevel(RF24_PA_MAX);
|
||||
radio.setDataRate(RF24_1MBPS);
|
||||
radio.setAutoAck(false);
|
||||
radio.disableCRC();
|
||||
radio.startListening();
|
||||
|
||||
delay(20);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
while (!updateLoop());
|
||||
radio.read(&datareceive, sizeof(datareceive));
|
||||
if (getChecksum((datareceive >> 8) & 0xFF) != datareceive & 0xFF){
|
||||
digitalWrite(errorLED, HIGH);
|
||||
}else{
|
||||
digitalWrite(errorLED, LOW);
|
||||
for (int i=0; i < tallyLEDlength; i++){
|
||||
digitalWrite(tallyLED[i], (datareceive >> 15 - i) & 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean updateLoop(){
|
||||
currentTime = millis();
|
||||
if (radio.available()){
|
||||
previousTime = currentTime;
|
||||
return true;
|
||||
}
|
||||
else if (currentTime - previousTime >= errorTime){
|
||||
digitalWrite(errorLED, HIGH);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t getChecksum(uint8_t data){
|
||||
uint8_t checksum = 0;
|
||||
for (int i=8; i<8; i++) checksum += (data >> i) & 1;
|
||||
return checksum;
|
||||
}
|
Loading…
Reference in New Issue