Skip to content

Instantly share code, notes, and snippets.

@theapi
Created November 25, 2013 17:04
Show Gist options
  • Save theapi/7644698 to your computer and use it in GitHub Desktop.
Save theapi/7644698 to your computer and use it in GitHub Desktop.
Very hacky listen to the wireless doorbell
int i, good, k, j, incoming;
int inPin = 3;
int led = 13;
int steps = 8;
int on = 0;
byte data_in;
void setup()
{
//attachInterrupt(1,data_incoming,RISING);
pinMode(inPin, INPUT);
pinMode(led, OUTPUT);
Serial.begin(9600); // Debugging only
Serial.println("setup");
}
void loop()
{
int buttonState = digitalRead(inPin);
if (buttonState == HIGH) {
// start monitoring the incoming signal
handle_incoming();
}
}
void handle_incoming() {
int start = 1;
int count = 0;
int last = 0;
//digitalWrite(led, HIGH);
k = 0;
Serial.println("\t handle_incoming");
// listen for 'steps' bytes of data
for (j=0; j< steps; i++) {
// store as byte
for (i=0; i<8; i++) {
if (start) {
// just entered the function
Serial.print(HIGH);
bitWrite(data_in, i, HIGH);
start = 0;
continue;
}
int buttonState = digitalRead(inPin);
//Serial.print(buttonState);
bitWrite(data_in, i, buttonState);
Serial.print(buttonState);
// end of byte
if (i == 7) {
if (int(data_in) > 0) {
//Serial.print(data_in);
count++;
} else {
// empty byte
k++;
}
last = data_in;
Serial.print("\tcount: ");
Serial.print(count);
Serial.println(" ");
// Empty the byte
data_in = 0;
// assume lots of data together is the button
if (count == 30) {
if (on) {
digitalWrite(led, LOW);
on = 0;
} else {
digitalWrite(led, HIGH);
on = 1;
}
}
}
//delay(100);
// to hear the unknown source use a very quick delay
delayMicroseconds(20);
}
if (k < steps) {
j = 0;
} else {
// listen no more
break;
}
}
Serial.println("\t\t finished_incoming");
//digitalWrite(led, LOW);
incoming = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment