-
Notifications
You must be signed in to change notification settings - Fork 0
/
rocket-lamp.ino
81 lines (60 loc) · 1.64 KB
/
rocket-lamp.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
#include <EEPROM.h>
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
#include <FastLED.h>
#define NUM_LEDS 16
#define DATA_PIN 3
#define CLOCK_PIN 13
#define DELAY 40
CRGB leds[NUM_LEDS];
#include "LedUtil.h"
#include "HttpServer.h"
#include "Patterns.h"
#include <ESP8266WiFi.h>
#include "WiFiConfig.h" //Define STASSID and STAPSK in WifiConfig.h or remove this and define below
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
/******************* FUNCTIONS **********************/
void setup() {
Serial.begin(115200);
Serial.println("Rocket Lamp");
EEPROM.begin(512);
loadSettings();
LEDS.addLeds<WS2812,DATA_PIN,GRB>(leds,NUM_LEDS);
LEDS.setBrightness(250);
setupWiFi();
setupHttpServer();
// setPattern(1); // force override eeprom
}
void loop() {
server.handleClient();
patterns[currentPatternIndex].pattern();
}
void loadSettings() {
currentPatternIndex = EEPROM.read(0);
if (currentPatternIndex < 0)
currentPatternIndex = 0;
else if (currentPatternIndex >= patternCount)
currentPatternIndex = patternCount - 1;
Serial.printf("loadSettings currentPatternIndex:%d\n", currentPatternIndex);
}
void setupWiFi() {
flashLeds(CRGB::Red, 2);
setColor(CRGB::White);
Serial.printf("Connecting to SSID: %s\n", ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
flashLeds(CRGB::Blue, 5);
}