Guest User

Untitled

a guest
May 10th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266mDNS.h>
  3. #include <WiFiUdp.h>
  4. #include <ArduinoOTA.h>
  5. #include <Adafruit_NeoPixel.h>
  6.  
  7. #ifndef STASSID
  8. #define STASSID ""
  9. #define STAPSK ""
  10. #endif
  11.  
  12. int neoPixelPin = 2;
  13. // How many NeoPixels we will be using, charge accordingly
  14. int numPixels = 8;
  15.  
  16. // Instatiate the NeoPixel from the ibrary
  17. Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixels, neoPixelPin, NEO_GRB + NEO_KHZ800);
  18.  
  19.  
  20. const char* ssid = STASSID;
  21. const char* password = STAPSK;
  22.  
  23. void setup() {
  24. Serial.begin(115200);
  25. Serial.println("Booting");
  26. WiFi.mode(WIFI_STA);
  27. WiFi.begin(ssid, password);
  28. while (WiFi.waitForConnectResult() != WL_CONNECTED) {
  29. Serial.println("Connection Failed! Rebooting...");
  30. delay(5000);
  31. ESP.restart();
  32. }
  33. ArduinoOTA.begin();
  34. Serial.println("Ready");
  35. Serial.print("IP address: ");
  36. Serial.println(WiFi.localIP());
  37.  
  38.  
  39.  
  40. strip.begin(); // initialize the strip
  41. strip.show(); // make sure it is visible
  42. strip.clear(); // Initialize all pixels to 'off'
  43.  
  44. uint8_t red1 = 0, green1 = 255, blue1 = 0;
  45. uint8_t red2 = 255, green2 = 100, blue2 = 100;
  46.  
  47. for (int i = 0; i < 50; i++)
  48. {
  49. uint8_t red = mix(red1, red2, i, 50);
  50. uint8_t green = mix(green1, green2, i, 50);
  51. uint8_t blue = mix(blue1, blue2, i, 50);
  52. strip.setPixelColor(i, red, green, blue);
  53. }
  54. }
  55.  
  56. void loop() {
  57. ArduinoOTA.handle();
  58. }
  59.  
  60. uint8_t mix(uint8_t a, uint8_t b, int pct, int range) {
  61. if (pct <= 0) return a;
  62. if (pct >= range) return b;
  63. return (((int32_t)a * (range-pct)) / range) + (((uint32_t)b * pct) / range);
  64. }
Add Comment
Please, Sign In to add comment