Advertisement
Guest User

OTA attempt

a guest
Dec 7th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. #define FASTLED_ALLOW_INTERRUPTS 0
  2. #include "FastLED.h"
  3. #include <ESP8266WiFi.h>
  4. #include <ESP8266mDNS.h>
  5. #include <WiFiUdp.h>
  6. #include <ArduinoOTA.h>
  7.  
  8. const char* ssid = "MyCharterWiFi3e-2G";
  9. const char* password = "unevenlotus916";
  10. const char* host = "SNOW_FLAKE";
  11.  
  12. FASTLED_USING_NAMESPACE
  13.  
  14. //int lightPin = A7; //define a pin for Photo resistor
  15.  
  16. #define NUM_STRIPS 4
  17. #define NUM_LEDS_PER_STRIP 28
  18. #define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS
  19.  
  20. CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
  21.  
  22. #define BRIGHTNESS 255
  23. #define FRAMES_PER_SECOND 120
  24.  
  25. void setup() {
  26. Serial.begin(115200);
  27. Serial.println("Booting");
  28. WiFi.mode(WIFI_STA);
  29. WiFi.begin(ssid, password);
  30. while (WiFi.waitForConnectResult() != WL_CONNECTED) {
  31. Serial.println("Connection Failed! Rebooting...");
  32. delay(5000);
  33. ESP.restart();
  34. }
  35.  
  36. // Port defaults to 8266
  37. // ArduinoOTA.setPort(8266);
  38.  
  39. // Hostname defaults to esp8266-[ChipID]
  40. ArduinoOTA.setHostname(host);
  41.  
  42. // No authentication by default
  43. // ArduinoOTA.setPassword((const char *)"123");
  44.  
  45. ArduinoOTA.onStart([]() {
  46. Serial.println("Start");
  47. });
  48. ArduinoOTA.onEnd([]() {
  49. Serial.println("\nEnd");
  50. });
  51. ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  52. Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  53. });
  54. ArduinoOTA.onError([](ota_error_t error) {
  55. Serial.printf("Error[%u]: ", error);
  56. if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
  57. else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
  58. else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
  59. else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
  60. else if (error == OTA_END_ERROR) Serial.println("End Failed");
  61. });
  62. ArduinoOTA.begin();
  63. Serial.println("Ready");
  64. Serial.print("IP address: ");
  65. Serial.println(WiFi.localIP());
  66.  
  67. // tell FastLED there's 60 NEOPIXEL leds on pin 10, starting at index 0 in the led array
  68. FastLED.addLeds<NEOPIXEL, D4>(leds, 0, NUM_LEDS_PER_STRIP);
  69.  
  70. // tell FastLED there's 60 NEOPIXEL leds on pin 11, starting at index 60 in the led array
  71. FastLED.addLeds<NEOPIXEL, D3>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
  72.  
  73. // tell FastLED there's 60 NEOPIXEL leds on pin 12, starting at index 120 in the led array
  74. FastLED.addLeds<NEOPIXEL, D2>(leds, 2 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
  75.  
  76. // tell FastLED there's 60 NEOPIXEL leds on pin 12, starting at index 120 in the led array
  77. FastLED.addLeds<NEOPIXEL, D1>(leds, 3 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
  78.  
  79. delay(5000); // 3 second delay for recovery
  80.  
  81. // tell FastLED about the LED strip configuration
  82. // FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  83. //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  84.  
  85. // set master brightness control
  86. // FastLED.setBrightness(analogRead(lightPin));
  87. FastLED.setBrightness(BRIGHTNESS);
  88.  
  89. }
  90.  
  91. void loop() {
  92. ArduinoOTA.handle();
  93. // brightness();
  94. pride();
  95. FastLED.show();
  96. }
  97.  
  98. void pride()
  99. {
  100. static uint16_t sPseudotime = 0;
  101. static uint16_t sLastMillis = 0;
  102. static uint16_t sHue16 = 0;
  103.  
  104. uint8_t sat8 = beatsin88( 87, 220, 250);
  105. uint8_t brightdepth = beatsin88( 341, 96, 224);
  106. uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
  107. uint8_t msmultiplier = beatsin88(147, 23, 60);
  108.  
  109. uint16_t hue16 = sHue16;//gHue * 256;
  110. uint16_t hueinc16 = beatsin88(113, 1, 3000);
  111.  
  112. uint16_t ms = millis();
  113. uint16_t deltams = ms - sLastMillis ;
  114. sLastMillis = ms;
  115. sPseudotime += deltams * msmultiplier;
  116. sHue16 += deltams * beatsin88( 400, 5,9);
  117. uint16_t brightnesstheta16 = sPseudotime;
  118.  
  119. for( uint16_t i = 0 ; i < NUM_LEDS; i++) {
  120. hue16 += hueinc16;
  121. uint8_t hue8 = hue16 / 256;
  122.  
  123. brightnesstheta16 += brightnessthetainc16;
  124. uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
  125.  
  126. uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
  127. uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
  128. bri8 += (255 - brightdepth);
  129.  
  130. CRGB newcolor = CHSV( hue8, sat8, bri8);
  131.  
  132. uint16_t pixelnumber = i;
  133. pixelnumber = (NUM_LEDS-1) - pixelnumber;
  134.  
  135. nblend( leds[pixelnumber], newcolor, 64);
  136. }
  137. }
  138.  
  139. /*void brightness(){
  140. int val = analogRead(lightPin);
  141. val = map(val, 0, 1023, 64, 255);
  142. FastLED.setBrightness(val);
  143. Serial.println(val); //Write the value of the photoresistor to the serial monitor.
  144.  
  145. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement