Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #include <ESP8266WiFi.h>
- //#include <ArduinoOTA.h>
- FASTLED_USING_NAMESPACE
- #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
- #warning "Requires FastLED 3.1 or later; check github for latest code."
- #endif
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- #define DATA_PIN 2
- //#define CLK_PIN 4
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- #define NUM_LEDS 96
- CRGB leds[NUM_LEDS];
- int BRIGHTNESS = 0;
- #define FRAMES_PER_SECOND 120
- const char *ssid = "Limettenporsche";
- const char *pass = "W!r3l355";
- WiFiServer server(80);
- void rainbow();
- void stat();
- void rainbowWithGlitter();
- void confetti();
- void sinelon();
- void juggle();
- void bpm();
- void nope();
- void noperb();
- void die();
- // List of patterns to cycle through. Each is defined as a separate function below.
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = { rainbow, stat, rainbowWithGlitter, confetti, sinelon, juggle, bpm, nope, noperb, die};
- uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
- uint8_t gHue = 0; // rotating "base color" used by many of the patterns
- int oneColor = 0;
- void setup() {
- delay(3000); // 3 second delay for recovery
- Serial.begin(115200);
- Serial.println();
- Serial.println("Configuring access point...");
- WiFi.mode(WIFI_AP_STA);
- WiFi.softAP(ssid, pass);
- IPAddress myIP = WiFi.softAPIP();
- Serial.print("AP IP Address: ");
- Serial.println(myIP);
- server.begin();
- // ArduinoOTA.onStart([]() {
- // String type;
- // if (ArduinoOTA.getCommand() == U_FLASH)
- // type = "sketch";
- // else // U_SPIFFS
- // type = "filesystem";
- //
- // // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
- // Serial.println("Start updating " + type);
- // });
- // ArduinoOTA.onEnd([]() {
- // Serial.println("\nEnd");
- // });
- // ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
- // Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
- // });
- // ArduinoOTA.onError([](ota_error_t error) {
- // Serial.printf("Error[%u]: ", error);
- // if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
- // else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
- // else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
- // else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
- // else if (error == OTA_END_ERROR) Serial.println("End Failed");
- // });
- // ArduinoOTA.begin();
- // tell FastLED about the LED strip configuration
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- // set master brightness control
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop()
- {
- //ArduinoOTA.handle();
- // Call the current pattern function once, updating the 'leds' array
- gPatterns[gCurrentPatternNumber]();
- // send the 'leds' array out to the actual LED strip
- FastLED.show();
- // insert a delay to keep the framerate modest
- // do some periodic updates
- if(!oneColor){ {
- gHue++; // slowly cycle the "base color" through the rainbow
- }
- }
- WiFiClient client = server.available();
- if (!client) {
- delay(20);
- return;
- }
- int i = 0;
- int bytes = client.available();
- while (!bytes) {
- bytes = client.available();
- i++;
- delay(1);
- if (i > 100) return; //timeout after 100 ms
- }
- char c;
- c = char(client.read());
- String line = "";
- String req = "";
- bytes--;
- if (c == 'P') { //it's probably a post request, process it
- while (bytes) {
- //we get the last line of the request
- c = char(client.read());
- line += c;
- if (c == '\n') {
- Serial.println("Line was");
- Serial.println(line);
- req = line;
- line = "";
- }
- bytes--;
- }
- }
- int command = line.toInt();
- Serial.println("\nGot Data:");
- Serial.println(req);
- Serial.println("\nGot Command");
- Serial.println(command);
- client.flush();
- if (command) {
- gCurrentPatternNumber = (command - 1) % ARRAY_SIZE( gPatterns ); //the modulo is just for safety
- }
- else{
- switch(line[0]){
- case 'a':
- Serial.println("toggling color-rainbow mode");
- oneColor = 1-oneColor;
- break;
- case 'r':
- gHue = 0; //red
- break;
- case 'g':
- gHue = 96; //green
- break;
- case 'b':
- gHue = 160; //blue
- break;
- case 'y':
- gHue = 64; //yellow
- break;
- case 'v':
- gHue = 200; //violet
- break;
- case 'c':
- gHue = 128; //cyan
- break;
- case 'h':
- BRIGHTNESS = 255;
- FastLED.setBrightness(BRIGHTNESS);
- break;
- case 'm':
- BRIGHTNESS = 127;
- FastLED.setBrightness(BRIGHTNESS);
- break;
- case 'l':
- BRIGHTNESS = 0;
- FastLED.setBrightness(BRIGHTNESS);
- break;
- }
- }
- //prepare a response
- String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n";
- s += "<form action = '' method = 'post'>";
- s += "<input type='submit' name='r' value='red' /><br />\n";
- s += "<input type='submit' name='g' value='green' /><br />\n";
- s += "<input type='submit' name='b' value='blue' /><br />\n";
- s += "<input type='submit' name='y' value='yellow' /><br />\n";
- s += "<input type='submit' name='v' value='violet' /><br />\n";
- s += "<input type='submit' name='c' value='cyan' /><br />\n";
- s += "<input type='submit' name='a' value='Toggle Rainbow Colors' /><br />\n";
- s += "<input type='submit' name='1' value='Solid/Rainbow'/><br />\n";
- s += "<input type='submit' name='2' value='Solid/Rainbow with Glitter'/><br />\n";
- s += "<input type='submit' name='3' value='Confetti'/><br />\n";
- s += "<input type='submit' name='4' value='Sinelon'/><br />\n";
- s += "<input type='submit' name='5' value='Juggle'/><br />\n";
- s += "<input type='submit' name='6' value='BPM'/><br />\n";
- s += "<input type='submit' name='7' value='kill me'/><br />\n";
- s += "<input type='submit' name='8' value='kill me US edition'/><br />\n";
- s += "<input type='submit' name='9' value='kill others'/><br />\n";
- s += "<input type='submit' name='h' value='On'/><br />\n";
- s += "<input type='submit' name='m' value='Half'/><br />\n";
- s += "<input type='submit' name='l' value='Off'/><br />\n";
- s += "</form>";
- s += "<p>Last Command Was ";
- s += line;
- s += "</p>\n";
- s += "</html>";
- client.print(s);
- delay(1);
- //EVERY_N_SECONDS( 10 ) {
- // nextPattern(); // change patterns periodically
- //}
- }
- void nextPattern()
- {
- // add one to the current pattern number, and wrap around at the end
- gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
- }
- void rainbow()
- {
- if(oneColor){
- fill_solid( leds, NUM_LEDS, CHSV(gHue, 200, 255));
- }
- else{
- // FastLED's built-in rainbow generator
- fill_rainbow( leds, NUM_LEDS, gHue, 7);
- }
- }
- void rainbowWithGlitter()
- {
- // built-in FastLED rainbow, plus some random sparkly glitter
- rainbow();
- addGlitter(80);
- }
- void addGlitter( fract8 chanceOfGlitter)
- {
- if ( random8() < chanceOfGlitter) {
- leds[ random16(NUM_LEDS) ] += CRGB::White;
- }
- }
- void confetti()
- {
- // random colored speckles that blink in and fade smoothly
- fadeToBlackBy( leds, NUM_LEDS, 10);
- int pos = random16(NUM_LEDS);
- if(!oneColor){
- leds[pos] += CHSV( gHue + random8(64), 200, 255);
- }
- else{
- leds[pos] += CHSV( gHue, 200, 255);
- }
- }
- void sinelon()
- {
- // a colored dot sweeping back and forth, with fading trails
- fadeToBlackBy( leds, NUM_LEDS, 50);
- int pos = beatsin88( 2600, 0, NUM_LEDS - 1 );
- leds[pos] += CHSV( gHue, 255, 192);
- }
- void bpm()
- {
- // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
- uint8_t BeatsPerMinute = 120;
- CRGBPalette16 palette = PartyColors_p;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for ( int i = 0; i < NUM_LEDS; i++) { //9948
- leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
- }
- }
- void juggle() {
- // eight colored dots, weaving in and out of sync with each other
- fadeToBlackBy( leds, NUM_LEDS, 20);
- byte dothue = gHue;
- for ( int i = 0; i < 8; i++) {
- leds[beatsin16( i + 7, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255);
- if(!oneColor)
- {
- dothue += 32;
- }
- }
- }
- void nope()
- {
- allblue();
- delay(20);
- allblack();
- delay(40);
- allblue();
- delay(20);
- allblack();
- delay(200);
- allblue();
- delay(20);
- allblack();
- delay(40);
- allblue();
- delay(20);
- allblack();
- delay(600);
- }
- void noperb()
- {
- allblue();
- delay(20);
- allblack();
- delay(40);
- allblue();
- delay(20);
- allblack();
- delay(200);
- allred();
- delay(20);
- allblack();
- delay(40);
- allred();
- delay(20);
- allblack();
- delay(600);
- }
- void die()
- {
- allred();
- delay(40);
- allblue();
- delay(40);
- }
- void allblack()
- {
- for (int dot = 0; dot < NUM_LEDS; dot++)
- {
- leds[dot] = CRGB::Black;
- }
- FastLED.show();
- }
- void allblue()
- {
- for (int dot = 0; dot < NUM_LEDS; dot++)
- {
- leds[dot] = CRGB::Blue;
- }
- FastLED.show();
- }
- void allred()
- {
- for (int dot = 0; dot < NUM_LEDS; dot++)
- {
- leds[dot] = CRGB::Red;
- }
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement