-
Notifications
You must be signed in to change notification settings - Fork 3
/
RGB_Strip_Control_ESP8266_Souliss.ino
129 lines (106 loc) · 4.46 KB
/
RGB_Strip_Control_ESP8266_Souliss.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**************************************************************************
Souliss - RGB LED Strip control from an ESP8266
This is a RGB LED Strip Driver/Controller driven by the Souliss Framework.
Load this code on ESP8266 board using the porting of the Arduino core
for this platform.
The 3 output control 3 IRLZ44N Mosfet.
In the actual configuration the channel are configured in this way:
Red channel = GPIO14
Green channel = GPIO4
Blue channel = GPIO5
Code is not yet optimised for any energy saving and will always be active.
DHCP is used to get the IP address. Use serial output (76800) to get the actual IP adress.
***************************************************************************/
// Let the IDE point to the Souliss framework
#include "SoulissFramework.h"
// Configure the framework
#include "bconf/MCU_ESP8266.h" // Load the code directly on the ESP8266
#include "conf/Gateway.h" // The main node is the Gateway, we have just one node
// Include framework code and libraries
#include <ESP8266WiFi.h>
#include "Souliss.h"
// **** Define the WiFi name and password ****
#define WIFICONF_INSKETCH
#define WiFi_SSID "YourWifiName"
#define WiFi_Password "YourWifiPassword"
// Include framework code and libraries
#include <ESP8266WiFi.h>
#include <EEPROM.h>
#include "Souliss.h"
// **** Define here the right pin for your ESP module ****
#define OUTPUTPIN BUILTIN_LED
#define LEDCONTROL 0 // This is the memory slot for the logic that handle the light
#define LEDRED 1 // This is the memory slot for the logic that handle the light
#define LEDGREEN 2 // This is the memory slot for the logic that handle the light
#define LEDBLUE 3 // This is the memory slot for the logic that handle the light
void setup()
{
delay(10);
Serial.begin(76800);
delay(20);
Serial.println("Going to initialize");
Initialize();
Serial.println("Initialisation finished");
// Connect to the WiFi network and get an address from DHCP
GetIPAddress();
//Uncomment the next line to define a fixed IP address (consult Soulis documentation for more info)
// SetIPAddress(ip_address, subnet_mask, ip_gateway);
SetAsGateway(myvNet_dhcp); // Set this node as gateway for SoulissApp
Serial.println("Received IP address: ");
Serial.println(WiFi.localIP());
// This is the vNet address for this node, used to communicate with other
// nodes in your Souliss network
SetAddress(0xAB01, 0xFF00, 0x0000);
SetAsPeerNode(0xAB02, 1);
Serial.println("Node set as peer");
Set_T16(LEDCONTROL);
// Define outputs pins
pinMode(4, OUTPUT); // Blue LED output
pinMode(5, OUTPUT); // Green LED output
pinMode(14, OUTPUT); // Red LED output
}
// Following variable are used to save souliss set LED value. Souliss use 8 bit PWM output (0-255),
// whereas ESP8266 have 10 bit PWM output (0-1023). The variable are used to make the conversion.
int ledBlue = 0;
int ledGreen = 0;
int ledRed = 0;
void loop()
{
// Here we start to play
EXECUTEFAST() {
UPDATEFAST();
FAST_10ms() { // We process the logic and relevant input and output every 10 milliseconds
Logic_T16(LEDCONTROL);
ledBlue = mOutput(LEDBLUE);
ledGreen = mOutput(LEDGREEN);
ledRed = mOutput(LEDRED);
if (ledBlue != 0) {
analogWrite(4, (ledBlue+1)*4);
} else {
analogWrite(4, 0);
}
if (ledGreen != 0) {
analogWrite(5, (ledGreen+1)*4);
} else {
analogWrite(5, 0);
}
if (ledRed != 0) {
analogWrite(14, (ledRed+1)*4);
} else {
analogWrite(14, 0);
}
ProcessCommunication();
}
// Here we handle here the communication with Android
FAST_GatewayComms();
}
EXECUTESLOW() {
UPDATESLOW();
SLOW_10s() {
// Timer associated to the LED logic control
Timer_T16(LEDCONTROL);
// Test phase output to ensure device is running
Serial.println("Device is still running ");
}
}
}