Created
October 28, 2012 13:28
-
-
Save Crenshinibon/3968599 to your computer and use it in GitHub Desktop.
Receiving pull-up simple RF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byte leftSideData[5]={0}; | |
uint8_t receivingIndex = 0; | |
boolean receiving = false; | |
const byte WAITING=0xE1,PULLUP=B10101010,PRE=0x5E,ADDR=0x10,NOTHING=0xFE,ERROR=0x77; | |
int receiveState = WAITING; | |
void loop(){ | |
byte in = receivePackage(); | |
if(in != NOTHING){ | |
Serial.print("package: "); | |
Serial.println(in,HEX); | |
} | |
} | |
uint8_t pullupCounter = 0; | |
static byte receivePackage(){ | |
byte erg = NOTHING; | |
if(receiveState == WAITING && Serial434.available()){ | |
byte in = Serial434.read(); | |
if(in == PULLUP){ | |
receiveState = PULLUP; | |
pullupCounter = 1; | |
} | |
else if(in == PRE){ | |
receiveState = PRE; | |
} | |
} | |
if(receiveState == PULLUP && Serial434.available()){ | |
byte in = Serial434.read(); | |
if(in == PRE){ | |
receiveState = PRE; | |
} | |
else if(in == PULLUP){ | |
pullupCounter ++; | |
Serial.print("pullup: "); | |
Serial.println(pullupCounter,DEC); | |
} | |
else if(in == ERROR){ | |
receiveState = WAITING; | |
} | |
if(pullupCounter > 13){ | |
pullupCounter = 0; | |
receiveState = WAITING; | |
} | |
} | |
if(receiveState == PRE && Serial434.available() > 2) { | |
byte addr = Serial434.read(); | |
//Serial.print("addr: "); | |
//Serial.println(addr); | |
byte data = Serial434.read(); | |
//Serial.print("data: "); | |
//Serial.println(data); | |
byte chck = Serial434.read(); | |
//Serial.print("check: "); | |
//Serial.println(chck); | |
if(addr == ADDR && addr + data == chck){ | |
erg = data; | |
} | |
else{ | |
erg = ERROR; | |
} | |
receiveState = WAITING; | |
} | |
return erg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment