You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md
4
+
* - ensure all dependent libraries are installed
5
+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide
6
+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies
7
+
* - open serial monitor and check whats happening
8
+
* - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk
9
+
* - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one
10
+
*/
11
+
12
+
// Uncomment the following line to enable serial debug output
13
+
//#define ENABLE_DEBUG
14
+
15
+
#ifdef ENABLE_DEBUG
16
+
#defineDEBUG_ESP_PORT Serial
17
+
#defineNODEBUG_WEBSOCKETS
18
+
#defineNDEBUG
19
+
#endif
20
+
21
+
#include<Arduino.h>
22
+
#ifdef ESP8266
23
+
#include<ESP8266WiFi.h>
24
+
#endif
25
+
#ifdef ESP32
26
+
#include<WiFi.h>
27
+
#endif
28
+
29
+
#include"SinricPro.h"
30
+
#include"SinricProLight.h"
31
+
32
+
#defineWIFI_SSID"YOUR-WIFI-SSID"
33
+
#defineWIFI_PASS"YOUR-WIFI-PASS"
34
+
#defineAPP_KEY"YOUR-APPKEY"// Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
35
+
#defineAPP_SECRET"YOUR-APPSECRET"// Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
36
+
#defineLIGHT_ID"YOUR-DEVICEID"// Should look like "5dc1564130xxxxxxxxxxxxxx"
37
+
#defineBAUD_RATE9600// Change baudrate to your need for serial log
38
+
39
+
#defineBLUE_PIN D5 // PIN for BLUE Mosfet - change this to your need (D5 = GPIO14 on ESP8266)
40
+
#defineRED_PIN D6 // PIN for RED Mosfet - change this to your need (D6 = GPIO12 on ESP8266)
41
+
#defineGREEN_PIN D7 // PIN for GREEN Mosfet - change this to your need (D7 = GPIO13 on ESP8266)
42
+
43
+
struct { // Stores current device state with following initial values:
44
+
bool powerState = false; // initial state is off
45
+
int brightness = 100; // initial brightness is set to 100
46
+
struct {
47
+
byte r = 255; // color
48
+
byte g = 255; // is set
49
+
byte b = 255; // to white
50
+
} color;
51
+
} device_state;
52
+
53
+
// setStripe: sets the mosfets values corresponding to values stored in device_state
54
+
voidsetStripe() {
55
+
int rValue = map(device_state.color.r * device_state.brightness, 0, 255 * 100, 0, 1023); // calculate red value and map between 0 and 1023 for analogWrite
56
+
intgValue = map(device_state.color.g * device_state.brightness, 0, 255 * 100, 0, 1023); // calculate green value and map between 0 and 1023 for analogWrite
57
+
int bValue = map(device_state.color.b * device_state.brightness, 0, 255 * 100, 0, 1023); // calculate blue value and map between 0 and 1023 for analogWrite
58
+
59
+
if (device_state.powerState == false) { // turn off?
60
+
digitalWrite(RED_PIN, LOW); // set
61
+
digitalWrite(GREEN_PIN, LOW); // mosfets
62
+
digitalWrite(BLUE_PIN, LOW); // low
63
+
} else {
64
+
analogWrite(RED_PIN, rValue); // write red value to pin
65
+
analogWrite(GREEN_PIN, gValue); // write green value to pin
66
+
analogWrite(BLUE_PIN, bValue); // write blue value to pin
0 commit comments