Created
March 20, 2022 14:00
-
-
Save SimedruF/18119d8bded0f79c29044056b75f672f to your computer and use it in GitHub Desktop.
ATTiny85_WindowOpen.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> | |
#ifdef F_CPU | |
#undef F_CPU | |
#define F_CPU 8000000 //value must be 1000000, 8000000 | |
#endif | |
#define Delay_time_ms 100 | |
#define Led 1 // Select the pin where the led is attached. Options: from 0 to 4 | |
#define WINDOW_OPEN_PIN 0// Select the pin where the RF transmitter is attached. | |
#define WINDOW_CLOSE_PIN 4// Select the pin where the RF transmitter is attached. | |
#define RF_SEND_PIN 2 // Select the pin where the touch button is attached | |
#define WINDOW_OPEN 0 | |
#define WINDOW_CLOSED 1 | |
#define VERSION "0.0.1" | |
RCSwitch mySwitch = RCSwitch(); | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(Led, OUTPUT); // initialize the digital pin as an output. | |
digitalWrite(Led, LOW); // Set it in Low state | |
pinMode(WINDOW_OPEN_PIN, INPUT); // initialize the digital pin as an input. | |
digitalWrite(WINDOW_OPEN_PIN, LOW); // Set it in Low state | |
pinMode(WINDOW_CLOSE_PIN, INPUT); // initialize the digital pin as an input. | |
digitalWrite(WINDOW_CLOSE_PIN, LOW); // Set it in Low state | |
// Transmitter is connected to Attiny Pin PB2 <-- | |
// That is physical pin2 | |
mySwitch.enableTransmit(RF_SEND_PIN); | |
// Optional set pulse length. | |
mySwitch.setPulseLength(208); | |
// Optional set protocol (default is 1, will work for most outlets) | |
mySwitch.setProtocol(1, 208); | |
// Optional set number of transmission repetitions. | |
mySwitch.setRepeatTransmit(7); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
// read the pushbutton input pin | |
int WindowOpenState = digitalRead(WINDOW_OPEN_PIN); | |
if(WindowOpenState == WINDOW_OPEN) | |
{ | |
for (int i=0; i<8; i++) | |
{ | |
/* send the activation code to the receiver*/ | |
mySwitch.send(5, 24); | |
delay(50); | |
digitalWrite(Led, HIGH); | |
delay(500); | |
digitalWrite(Led, LOW); | |
} | |
} | |
else | |
{ | |
mySwitch.send(9, 24); | |
delay(Delay_time_ms); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment