Amazing Idea Using Plastic Glass and RGB LED Strip
Hello friends, this is cool idea using plastic glass and RGB LED strip. This projects is cool because in this project you will get wifi option to control rgb led from your smart phone. This is very simple just follow all the step and make your own RGB Light.
Diagram:
1) WS2812B led strip 60led/m : https://roboman.in/qtch
2) ws2812B led strip 20led/m : https://roboman.in/6r9a
3) TTP223 Touch switch : https://roboman.in/j7k4
4) Arduino Nano: https://roboman.in/59h4
5) Arduino Nano Type C : https://roboman.in/xkfu
6) Esp 01 8266 Module : https://roboman.in/mqt5
7) 18650 Lithium Battery 2500mah 3C :https://roboman.in/utwc
8) 18650 Lithium Battery 2600mah 3C :https://roboman.in/mmab
9) 18650 Lithium Battery 2200mah 1C :https://roboman.in/70b5
10) 18650 Lithium Battery 2000mah 1C :https://roboman.in/7em9
11) 18650 Lithium Battery 1800mah 1C :https://roboman.in/ywss
Code All IN One :
Code:
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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
#ifdef ARDUINO_ARCH_ESP32 #include <WiFi.h> #include <WebServer.h> #define WEB_SERVER WebServer #define ESP_RESET ESP.restart() #else #include <ESP8266WiFi.h> #include <ESP8266WebServer.h> #define WEB_SERVER ESP8266WebServer #define ESP_RESET ESP.reset() #endif #include <WS2812FX.h> extern const char index_html[]; extern const char main_js[]; #define WIFI_SSID "RGB LAMP" #define WIFI_PASSWORD "12345678" //#define STATIC_IP // uncomment for static IP, set IP below #ifdef STATIC_IP IPAddress ip(192,168,0,123); IPAddress gateway(192,168,0,1); IPAddress subnet(255,255,255,0); #endif // QUICKFIX...See https://github.com/esp8266/Arduino/issues/263 #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define LED_PIN 1 // 0 = GPIO0, 2=GPIO2 #define LED_COUNT 45 #define TOUCH_SW 0 #define WIFI_TIMEOUT 30000 // checks WiFi every ...ms. Reset after this time, if WiFi cannot reconnect. #define HTTP_PORT 80 int SHORT_TIME = 2000; /* Time that will be considered as the short press time */ long ON_Duration;/* Variable that will store the value of time for which the button is pressed */ int previousState = LOW; /* Setting the initial state of push button HIGH as we are using the INPUT_PULLUP mode */ int presentState; /* Variable that will store the present state if the button*/ unsigned long press_Time = 0; /* Time at which the button was pressed */ unsigned long release_Time = 0;/*Time at which the button is released */ unsigned long auto_last_change = 0; unsigned long last_wifi_check_time = 0; String modes = ""; uint8_t myModes[] = {}; // *** optionally create a custom list of effect/mode numbers bool auto_cycle = false; int on_off=0; WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); WEB_SERVER server(HTTP_PORT); void stopled(){ modes.reserve(5000); modes_setup(); ws2812fx.init(); ws2812fx.setMode(FX_MODE_STATIC); ws2812fx.setColor(0xFF5900); ws2812fx.setSpeed(1000); ws2812fx.setBrightness(128); ws2812fx.stop(); } void startled(){ modes.reserve(5000); modes_setup(); ws2812fx.init(); ws2812fx.setMode(FX_MODE_STATIC); ws2812fx.setColor(0xFF5900); ws2812fx.setSpeed(1000); ws2812fx.setBrightness(128); ws2812fx.start(); } void setup(){ Serial.begin(115200); delay(500); Serial.println("\n\nStarting..."); pinMode(TOUCH_SW, INPUT); stopled(); //wifi_setup(); } void loop() { // Read the state of the switch/button: presentState = digitalRead(TOUCH_SW);/* Getting the present state of the push button */ long ON_TIME=0; // if(previousState == HIGH && presentState == LOW) /* If button is pressed */{ if(previousState == LOW && presentState == HIGH){ press_Time = millis();/* Save the time in milliseconds using the Millis function */ } //else if(previousState == LOW && presentState == HIGH) { /* If button is released*/ else if(previousState == HIGH && presentState == LOW){ release_Time = millis();/* save the time at which the button was released */ ON_TIME= release_Time - press_Time;/* calculating the time for which the button remained in the LOW state*/ //ON_TIME= press_Time-release_Time; Serial.println(ON_TIME); if( ON_TIME > SHORT_TIME ) /* comparing the value of time for which the button is pressed to the value for short press time*/ { Serial.println("Button is pressed for a long time ");/* printing the data on the serial monitor */ if(on_off==0){ on_off=1; startled(); wifi_setup(); ON_TIME=0; } else{ on_off=0; ws2812fx.stop(); } }else{ Serial.println("single press code"); if(on_off==1){ uint8_t next_mode = (ws2812fx.getMode() + 1) % ws2812fx.getModeCount(); ws2812fx.setMode(next_mode); Serial.print("mode is "); Serial.println(ws2812fx.getModeName(ws2812fx.getMode())); ON_TIME=0; } } } previousState = presentState;/* saving the present value in the previous value */ /* if(now - last_wifi_check_time > WIFI_TIMEOUT) { Serial.print("Checking WiFi... "); if(WiFi.status() != WL_CONNECTED) { Serial.println("WiFi connection lost. Reconnecting..."); wifi_setup(); } else { Serial.println("OK"); } last_wifi_check_time = now; }*/ if(on_off==1){ unsigned long now = millis(); server.handleClient(); ws2812fx.service(); if(auto_cycle && (now - auto_last_change > 10000)) { // cycle effect mode every 10 seconds uint8_t next_mode = (ws2812fx.getMode() + 1) % ws2812fx.getModeCount(); if(sizeof(myModes) > 0) { // if custom list of modes exists for(uint8_t i=0; i < sizeof(myModes); i++) { if(myModes[i] == ws2812fx.getMode()) { next_mode = ((i + 1) < sizeof(myModes)) ? myModes[i + 1] : myModes[0]; break; } } } ws2812fx.setMode(next_mode); Serial.print("mode is "); Serial.println(ws2812fx.getModeName(ws2812fx.getMode())); auto_last_change = now; } }else{ stopled(); } } /* * Connect to WiFi. If no connection is made within WIFI_TIMEOUT, ESP gets resettet. */ void wifi_setup(){ Serial.println("Wifi setup"); /* You can remove the password parameter if you want the AP to be open. */ WiFi.softAP(WIFI_SSID, WIFI_PASSWORD); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); Serial.println("HTTP server setup"); server.on("/", srv_handle_index_html); server.on("/main.js", srv_handle_main_js); server.on("/modes", srv_handle_modes); server.on("/set", srv_handle_set); server.onNotFound(srv_handle_not_found); server.begin(); Serial.println("HTTP server started."); Serial.println("ready!"); } /* void wifi_setup() { Serial.println(); Serial.print("Connecting to "); Serial.println(WIFI_SSID); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); WiFi.mode(WIFI_STA); #ifdef STATIC_IP WiFi.config(ip, gateway, subnet); #endif unsigned long connect_start = millis(); while(WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); if(millis() - connect_start > WIFI_TIMEOUT) { Serial.println(); Serial.print("Tried "); Serial.print(WIFI_TIMEOUT); Serial.print("ms. Resetting ESP now."); ESP_RESET; } } Serial.println(""); Serial.println("WiFi connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); Serial.println(); } */ /* * Build <li> string for all modes. */ void modes_setup() { modes = ""; uint8_t num_modes = sizeof(myModes) > 0 ? sizeof(myModes) : ws2812fx.getModeCount(); for(uint8_t i=0; i < num_modes; i++) { uint8_t m = sizeof(myModes) > 0 ? myModes[i] : i; modes += "<li><a href='#'>"; modes += ws2812fx.getModeName(m); modes += "</a></li>"; } } /* ##################################################### # Webserver Functions ##################################################### */ void srv_handle_not_found() { server.send(404, "text/plain", "File Not Found"); } void srv_handle_index_html() { server.send_P(200,"text/html", index_html); } void srv_handle_main_js() { server.send_P(200,"application/javascript", main_js); } void srv_handle_modes() { server.send(200,"text/plain", modes); } void srv_handle_set() { for (uint8_t i=0; i < server.args(); i++){ if(server.argName(i) == "c") { uint32_t tmp = (uint32_t) strtol(server.arg(i).c_str(), NULL, 10); if(tmp <= 0xFFFFFF) { ws2812fx.setColor(tmp); } } if(server.argName(i) == "m") { uint8_t tmp = (uint8_t) strtol(server.arg(i).c_str(), NULL, 10); uint8_t new_mode = sizeof(myModes) > 0 ? myModes[tmp % sizeof(myModes)] : tmp % ws2812fx.getModeCount(); ws2812fx.setMode(new_mode); auto_cycle = false; Serial.print("mode is "); Serial.println(ws2812fx.getModeName(ws2812fx.getMode())); } if(server.argName(i) == "b") { if(server.arg(i)[0] == '-') { ws2812fx.setBrightness(ws2812fx.getBrightness() * 0.8); } else if(server.arg(i)[0] == ' ') { ws2812fx.setBrightness(min(max(ws2812fx.getBrightness(), 5) * 1.2, 255)); } else { // set brightness directly uint8_t tmp = (uint8_t) strtol(server.arg(i).c_str(), NULL, 10); ws2812fx.setBrightness(tmp); } Serial.print("brightness is "); Serial.println(ws2812fx.getBrightness()); } if(server.argName(i) == "s") { if(server.arg(i)[0] == '-') { ws2812fx.setSpeed(max(ws2812fx.getSpeed(), 5) * 1.2); } else if(server.arg(i)[0] == ' ') { ws2812fx.setSpeed(ws2812fx.getSpeed() * 0.8); } else { uint16_t tmp = (uint16_t) strtol(server.arg(i).c_str(), NULL, 10); ws2812fx.setSpeed(tmp); } Serial.print("speed is "); Serial.println(ws2812fx.getSpeed()); } if(server.argName(i) == "a") { if(server.arg(i)[0] == '-') { auto_cycle = false; } else { auto_cycle = true; auto_last_change = 0; } } } server.send(200, "text/plain", "OK"); } |