Skip to content

Commit 49af939

Browse files
author
bitluni
committed
Added rf remote features
1 parent f3b3662 commit 49af939

9 files changed

+105
-13
lines changed

Fader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ by bitluni 2016
44
https://creativecommons.org/licenses/by/4.0/
55
Attribution means you can use it however you like as long you
66
mention that it's base on my stuff.
7-
I'll be pleased if you'd do it ba sharing http://youtube.com/bitlunislab
7+
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
88
*/
99

1010
template<class T>

LedFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ by bitluni 2016
44
https://creativecommons.org/licenses/by/4.0/
55
Attribution means you can use it however you like as long you
66
mention that it's base on my stuff.
7-
I'll be pleased if you'd do it ba sharing http://youtube.com/bitlunislab
7+
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
88
*/
99

1010
#include <ESP8266WebServer.h>

LedStates.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ by bitluni 2016
44
https://creativecommons.org/licenses/by/4.0/
55
Attribution means you can use it however you like as long you
66
mention that it's base on my stuff.
7-
I'll be pleased if you'd do it ba sharing http://youtube.com/bitlunislab
7+
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
88
*/
99

1010
#include <ESP8266WebServer.h>

PinStates.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ by bitluni 2016
44
https://creativecommons.org/licenses/by/4.0/
55
Attribution means you can use it however you like as long you
66
mention that it's base on my stuff.
7-
I'll be pleased if you'd do it ba sharing http://youtube.com/bitlunislab
7+
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
88
*/
99

1010
#include <ESP8266WebServer.h>

RF.h

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Released under Creative Commons Attribution 4.0
3+
by bitluni 2016
4+
https://creativecommons.org/licenses/by/4.0/
5+
Attribution means you can use it however you like as long you
6+
mention that it's base on my stuff.
7+
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
8+
*/
9+
10+
//Works with BH9938 with t=200
11+
12+
inline void rfPreamble(const int pin, const int t)
13+
{
14+
int m = micros();
15+
digitalWrite(pin, 1);
16+
while(micros() - m < t);
17+
digitalWrite(pin, 0);
18+
while(micros() - m < t * 32);
19+
}
20+
21+
inline void rfWriteBit(const int pin, const int t, int b)
22+
{
23+
int m = micros();
24+
if(b)
25+
{
26+
digitalWrite(pin, 1);
27+
while(micros() - m < t * 3);
28+
digitalWrite(pin, 0);
29+
while(micros() - m < t * 4);
30+
}
31+
else
32+
{
33+
digitalWrite(pin, 1);
34+
while(micros() - m < t);
35+
digitalWrite(pin, 0);
36+
while(micros() - m < t * 4);
37+
}
38+
}
39+
40+
inline void rfWriteByte(const int pin, const int t, int b)
41+
{
42+
rfWriteBit(pin, t, b & 128);
43+
rfWriteBit(pin, t, b & 64);
44+
rfWriteBit(pin, t, b & 32);
45+
rfWriteBit(pin, t, b & 16);
46+
rfWriteBit(pin, t, b & 8);
47+
rfWriteBit(pin, t, b & 4);
48+
rfWriteBit(pin, t, b & 2);
49+
rfWriteBit(pin, t, b & 1);
50+
}
51+
52+
void rfWriteCode(const int pin, const int t, int byte1, int byte2, int byte3)
53+
{
54+
rfPreamble(pin, t);
55+
rfWriteByte(pin, t, byte1);
56+
rfWriteByte(pin, t, byte2);
57+
rfWriteByte(pin, t, byte3);
58+
}
59+
60+
61+
62+

RainbowFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ by bitluni 2016
44
https://creativecommons.org/licenses/by/4.0/
55
Attribution means you can use it however you like as long you
66
mention that it's base on my stuff.
7-
I'll be pleased if you'd do it ba sharing http://youtube.com/bitlunislab
7+
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
88
*/
99

1010
#include "LedFunction.h"

SimpleRGBFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ by bitluni 2016
44
https://creativecommons.org/licenses/by/4.0/
55
Attribution means you can use it however you like as long you
66
mention that it's base on my stuff.
7-
I'll be pleased if you'd do it ba sharing http://youtube.com/bitlunislab
7+
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
88
*/
99

1010
#include "LedFunction.h"

WaveFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ by bitluni 2016
44
https://creativecommons.org/licenses/by/4.0/
55
Attribution means you can use it however you like as long you
66
mention that it's base on my stuff.
7-
I'll be pleased if you'd do it ba sharing http://youtube.com/bitlunislab
7+
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
88
*/
99

1010
#include <math.h>

bitluniHomeAutomation.ino

+36-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ by bitluni 2016
44
https://creativecommons.org/licenses/by/4.0/
55
Attribution means you can use it however you like as long you
66
mention that it's base on my stuff.
7-
I'll be pleased if you'd do it ba sharing http://youtube.com/bitlunislab
7+
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
88
*/
99

1010
#include <ESP8266WiFi.h>
@@ -20,9 +20,10 @@ I'll be pleased if you'd do it ba sharing http://youtube.com/bitlunislab
2020
#include "RainbowFunction.h"
2121
#include "SimpleRGBFunction.h"
2222
#include "WaveFunction.h"
23+
#include "RF.h"
2324

24-
const char* ssid = "....";
25-
const char* password = "....";
25+
const char* ssid = "...";
26+
const char* password = "...";
2627

2728
ESP8266WebServer server(80);
2829

@@ -45,8 +46,9 @@ void handleRoot() {
4546
message += "<a href='/setleds?r=32&g=64&b=32&fade=1000'>/setleds</a> sets LEDs to the color from arguments: r=<0..255> g=<0..255> b=<0..255><br>";
4647
message += "<a href='/ledsoff?fade=500'>/ledsoff</a> turns off LEDs<br>";
4748
message += "<a href='/setpins?D1=128&D2=256&D3=512'>/setpins</a> sets to any of the in arguments specified pins (D0..D8) to their PWM values (0..1023). To use them digital: 0=off, 1023=on<br>";
48-
message += "<a href='/togglepins'>/togglepins</a> inverts all pin values form pins used before.<br><br>";
49-
message += "All functions except togglepins support the argument 'fade' which specifies the milliseconds it takes to fade to the new specified state. ...nice blending ;-)<br>";
49+
message += "<a href='/togglepins'>/togglepins</a> inverts all pin values form pins used before.<br>";
50+
message += "<a href='/rf?D=6&id0=182&id1=182&channel=0&on=1'>/rf</a> sends a rf code from arguments: D=<0..8> id0=<0..255> id1=<0..255> channel=<1..7> on=<0..1><br><br>";
51+
message += "All functions except togglepins and rf support the argument 'fade' which specifies the milliseconds it takes to fade to the new specified state. ...nice blending ;-)<br>";
5052
message += "<br>Syntax is as follows: http://&ltip>/&ltcommand>?&ltargument1>=&ltvalue1>&&ltargument2>=&ltvalue2>&...<br>";
5153
message += "You can click on each link to see an example.<br><br>";
5254
message += "have fun -<a href='http://youtube.com/bitlunislab'>bitluni</a></body></html>";
@@ -88,6 +90,32 @@ bool checkFadeAndSetLedFunction(LedFunction *f)
8890
currentLedStates.setFunction(f);
8991
}
9092

93+
void handleRf()
94+
{
95+
const int pinNumbers[] = {D0, D1, D2, D3, D4, D5, D6, D7, D8};
96+
const int RF_MICROS = 200;
97+
int pin = getArgValue("D");
98+
int id0 = getArgValue("id0");
99+
int id1 = getArgValue("id1");
100+
int ch = getArgValue("channel");
101+
int on = getArgValue("on");
102+
String out = "rf D";
103+
out += pin;
104+
out += " ";
105+
out += id0;
106+
out += " ";
107+
out += id1;
108+
out += " ";
109+
out += ch;
110+
out += " ";
111+
out += on;
112+
pinMode(pinNumbers[pin], OUTPUT);
113+
for(int i = 0; i < 5; i++)
114+
rfWriteCode(pinNumbers[pin], RF_MICROS, id0, id1, ch | (on > 0? 8: 0));
115+
//if(pin == -1) return;
116+
server.send(200, "text/plain", out);
117+
}
118+
91119
void setup(void){
92120
Serial.begin(115200);
93121
WiFi.begin(ssid, password);
@@ -158,10 +186,12 @@ void setup(void){
158186
});
159187

160188
server.on("/pinsoff", [](){
161-
server.send(200, "text/plain", "insoff");
189+
server.send(200, "text/plain", "pinsoff");
162190
currentPinStates.setAllTo(0);
163191
currentPinStates.commit();
164192
});
193+
194+
server.on("/rf", handleRf);
165195

166196
server.onNotFound(handleNotFound);
167197

0 commit comments

Comments
 (0)