Created
March 20, 2022 13:54
-
-
Save SimedruF/e8c5fa1ce834e79d02e4ba4f64e4e394 to your computer and use it in GitHub Desktop.
ATMega2560_WindowOpenReceiver.ino
This file contains hidden or 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
/* | |
Florin Simedru | |
Complete project details at https://automatic-house.blogspot.com | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files. | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
*/ | |
#include <RCSwitch.h> | |
#include <Arduino.h> | |
#define LED LED_BUILTIN | |
RCSwitch mySwitch = RCSwitch(); | |
#define WINDOW_CLOSED 9 //defines incoming data set by user which is transmitted | |
#define WINDOW_OPEN 5 | |
void process(); | |
void setup() | |
{ | |
Serial.begin(115200); | |
pinMode(LED,OUTPUT); | |
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2 pinMode(led,OUTPUT); | |
Serial.print("Setup ok !"); | |
} | |
void loop() | |
{ | |
digitalWrite(LED,LOW); | |
if (mySwitch.available()) | |
{ | |
Serial.println("mySwitch.available !"); | |
int value = mySwitch.getReceivedValue(); | |
if (value == 0) { | |
Serial.print("Unknown encoding"); | |
} | |
else | |
{ | |
// used for checking received data | |
Serial.print("Received "); | |
Serial.print( mySwitch.getReceivedValue() ); | |
Serial.print(" / "); | |
Serial.print( mySwitch.getReceivedBitlength() ); | |
Serial.print("bit "); | |
Serial.print("Protocol: "); | |
Serial.println( mySwitch.getReceivedProtocol() ); | |
//digitalWrite(LED,HIGH); | |
} | |
if (mySwitch.getReceivedValue()) | |
{ | |
process(); | |
} | |
mySwitch.resetAvailable(); | |
Serial.println(" "); | |
} | |
digitalWrite(LED,HIGH ); | |
delay(200); | |
} | |
void process() | |
{ | |
unsigned long res = mySwitch.getReceivedValue(); | |
switch (res) | |
{ | |
case WINDOW_OPEN: | |
Serial.println("Window Open!"); | |
digitalWrite(LED,HIGH); | |
break; | |
case WINDOW_CLOSED: | |
Serial.println("Window closed!"); | |
digitalWrite(LED,LOW); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment