Changed everything =D

This commit is contained in:
Lukas Bachschwell 2016-07-30 17:11:04 +02:00
parent 9d6ebfba95
commit 5d030e9576

View File

@ -1,16 +1,20 @@
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
#ifdef __AVR__ #ifdef __AVR__
#include <avr/power.h> #include <avr/power.h>
#endif #endif
//Important: Set the number of LEDs here!!! #define PIN D6
#define PIN 6 #define NUMPIXELS 28
#define NUMPIXELS 22 Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//Create the object representation of our strip #include <ESP8266WiFi.h>
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); #include <DNSServer.h>
#include <ESP8266WebServer.h>
//Some usefull variables and buffers, currently not all in use const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);
unsigned long previousMillis = 0; unsigned long previousMillis = 0;
unsigned long interval = 0; unsigned long interval = 0;
int mode = 0; int mode = 0;
@ -20,34 +24,272 @@ int colorval1 = 0;
int colorval2 = 0; int colorval2 = 0;
int colorval3 = 0; int colorval3 = 0;
String responseHTML = ""
"<!DOCTYPE html><html><head><title>LedControl</title></head><body>"
"<h1>Control</h1><br> "
"<a style='font-size:100px;' href='http://192.168.1.1/on'>on</a><br><br><a style='font-size:100px;'href='http://192.168.1.1/off'>off</a>"
"<br><a style='font-size:100px;' href='http://192.168.1.1/1'>run</a></body><br><a style='font-size:100px;' href='http://192.168.1.1/3'>run single</a><br><a style='font-size:100px;' href='http://192.168.1.1/2'>freaky</a></body></html>"
"<br><a style='font-size:100px;' href='http://192.168.1.1/show&num=0'>0</a><br>"
"<a style='font-size:100px;' href='http://192.168.1.1/show&num=1'>1</a><br>"
"<a style='font-size:100px;' href='http://192.168.1.1/show&num=2'>2</a><br>"
"<a style='font-size:100px;' href='http://192.168.1.1/show&num=3'>3</a><br>"
"<a style='font-size:100px;' href='http://192.168.1.1/show&num=4'>4</a><br>"
"<a style='font-size:100px;' href='http://192.168.1.1/show&num=5'>5</a><br>";
void handleOn() {
mode = 0;
for (int i = 0; i < NUMPIXELS; i++) {
strip.setPixelColor(i, strip.Color(200, 50, 0)); // Moderately bright green color.
}
strip.show();
webServer.send(200, "text/html", responseHTML);
}
void handle1() {
mode = 1;
Serial.println("LOL");
webServer.send(200, "text/html", responseHTML);
}
void handle2() {
mode = 2;
Serial.println("LOL2");
webServer.send(200, "text/html", responseHTML);
}
void handle3() {
mode = 3;
Serial.println("LOL3");
webServer.send(200, "text/html", responseHTML);
}
void handleOff() {
mode = 0;
for (int i = 0; i < NUMPIXELS; i++) {
strip.setPixelColor(i, strip.Color(0, 0, 0)); // off
}
strip.show();
webServer.send(200, "text/html", responseHTML);
}
void handleShow() {
Serial.println(webServer.args());
}
void setup() { void setup() {
pixels.begin(); strip.begin();
Serial.begin(115200);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("Scary?");
// if DNSServer is started with "*" for domain name, it will reply with
// provided IP to all DNS request
dnsServer.start(DNS_PORT, "*", apIP);
webServer.on("/on", handleOn);
webServer.on("/off", handleOff);
webServer.on("/show", handleShow);
webServer.on("/1", handle1);
webServer.on("/2", handle2);
webServer.on("/3", handle3);
webServer.onNotFound([]() {
webServer.send(200, "text/html", responseHTML);
});
webServer.begin();
} }
void loop() { void loop() {
dnsServer.processNextRequest();
webServer.handleClient();
if(element<NUMPIXELS)
element++;
else
element = 0;
for(int i = 0; i < NUMPIXELS; i++){ if (millis() - previousMillis >= interval) {
//Set the color values for all leds as pixels.Color(G,R,B); // save the last time you blinked the LED
pixels.setPixelColor(i,pixels.Color(((i==element)?255 :0),((i==element)?0:0),((i==element)?0:255))); // Moderately bright green color. previousMillis = millis();
switch(mode){
case 1:
interval = 100;
if(element<NUMPIXELS) {
element++;
}
else {
element = 0;
colorval1 = ((colorval1==50)? 0:50);
}
strip.setPixelColor(element, strip.Color(255,colorval1,0)); // Moderately bright green color.
strip.show();
break;
case 2:
interval = 10;
if(colorval2 == 0)colorval1--;
else colorval1++;
if(colorval1 > 150) colorval2=0;
if(colorval1 < 30) colorval2=1;
for(int i=0;i<NUMPIXELS;i++){
strip.setPixelColor(i, strip.Color(colorval1,colorval1,colorval1));
}
strip.show();
break;
case 3:
interval = 100;
if(element<NUMPIXELS)
element++;
else
element = 0;
for(int i = 0; i < NUMPIXELS; i++){
strip.setPixelColor(i,strip.Color(((i==element)?100:200),((i==element)?100:50),((i==element)?100:0))); // Moderately bright green color.
}
strip.show();
default:
break;
}
previousMillis = millis();
} }
/*
for(int i = 0; i < NUMPIXELS; i++){ }
if(i%2)pixels.setPixelColor(i,pixels.Color(0,0,255));
else pixels.setPixelColor(i,pixels.Color(255,0,0));
}
*/
//this sends the data from our object to the actuall strip void startShow(int i) {
pixels.show(); mode = 0;
delay(200); switch (i) {
case 0: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
break;
case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red
break;
case 2: colorWipe(strip.Color(0, 255, 0), 50); // Green
break;
case 3: colorWipe(strip.Color(0, 0, 255), 50); // Blue
break;
case 4: theaterChase(strip.Color(127, 127, 127), 50); // White
break;
case 5: theaterChase(strip.Color(127, 0, 0), 50); // Red
break;
case 6: theaterChase(strip.Color( 0, 0, 127), 50); // Blue
break;
case 7: rainbow(20);
break;
case 8: rainbowCycle(20);
break;
case 9: theaterChaseRainbow(50);
break;
}
}
//####### Neopixeltricks
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i + j) & 255));
}
strip.show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
for (int q = 0; q < 3; q++) {
for (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j = 0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q = 0; q < 3; q++) {
for (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} }