Commit a557f225 authored by Mitchell Pomery's avatar Mitchell Pomery

Now with 90% less blockyness

parent 049f6495
...@@ -298,7 +298,7 @@ void colourWipe(uint32_t c, uint8_t wait) { ...@@ -298,7 +298,7 @@ void colourWipe(uint32_t c, uint8_t wait) {
strip.show(); strip.show();
delay(wait); delay(wait);
position++; position++;
if (position > STRIPLENGTH) { if (position >= STRIPLENGTH) {
position = 256; position = 256;
} }
} }
...@@ -308,12 +308,16 @@ void colourWipe(uint32_t c, uint8_t wait) { ...@@ -308,12 +308,16 @@ void colourWipe(uint32_t c, uint8_t wait) {
* @param wait delay between colour changes * @param wait delay between colour changes
*/ */
void rainbow(uint8_t wait) { void rainbow(uint8_t wait) {
for(int i = 0; i <strip.numPixels(); i++) { int outOf = 256;
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+position) & 255)); strip.setPixelColor(i, Wheel((i+position) & 255));
} }
strip.show(); strip.show();
delay(wait); delay(wait);
position++; position++;
if (position > outOf) {
position = 0;
}
} }
/** /**
...@@ -321,15 +325,16 @@ void rainbow(uint8_t wait) { ...@@ -321,15 +325,16 @@ void rainbow(uint8_t wait) {
* @param wait delay between colour changes * @param wait delay between colour changes
*/ */
void rainbowCycle(uint8_t wait) { void rainbowCycle(uint8_t wait) {
uint16_t j; int outOf = 256 * 5;
for(int j = 0; j < 256 * 5; j++) { // 5 cycles of all colours on wheel uint16_t i;
strip.setPixelColor(position, Wheel(((position * 256 / strip.numPixels()) + j) & 255)); for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + position) & 255));
} }
strip.show(); strip.show();
delay(wait); delay(wait);
position++; position++;
if (position > STRIPLENGTH) { if (position >= outOf) {
position = 256; position = 0;
} }
} }
...@@ -340,20 +345,21 @@ void rainbowCycle(uint8_t wait) { ...@@ -340,20 +345,21 @@ void rainbowCycle(uint8_t wait) {
*/ */
void theaterChase(uint32_t c, uint8_t wait) { void theaterChase(uint32_t c, uint8_t wait) {
///TODO: stop this blocking. Somehow ///TODO: stop this blocking. Somehow
for (int j=0; j<10; j++) { // do 10 cycles of chasing int outOf = 10;
for (int q=0; q < 3; q++) { for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) { for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); // turn every third pixel on strip.setPixelColor(i+q, c); // turn every third pixel on
} }
strip.show(); strip.show();
delay(wait);
delay(wait); for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); // turn every third pixel off
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); // turn every third pixel off
}
} }
} }
position++;
if (position >= outOf) {
position = 0;
}
} }
/** /**
...@@ -362,20 +368,24 @@ void theaterChase(uint32_t c, uint8_t wait) { ...@@ -362,20 +368,24 @@ void theaterChase(uint32_t c, uint8_t wait) {
*/ */
void theaterChaseRainbow(uint8_t wait) { void theaterChaseRainbow(uint8_t wait) {
///TODO: stop this blocking. Somehow ///TODO: stop this blocking. Somehow
for (int j=0; j < 256; j++) { // cycle all 256 colours in the wheel int outOf = 256;
for (int q=0; q < 3; q++) { for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) { for (int i=0; i < strip.numPixels(); i=i+3) {
// turn every third pixel on // turn every third pixel on
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); strip.setPixelColor(i+q, Wheel( (i+position) % 255));
} }
strip.show(); strip.show();
delay(wait); delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) { for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); // turn every third pixel off strip.setPixelColor(i+q, 0); // turn every third pixel off
} }
} }
position++;
if (position >= outOf) {
position = 0;
} }
} }
...@@ -402,8 +412,12 @@ uint32_t Wheel(byte WheelPos) { ...@@ -402,8 +412,12 @@ uint32_t Wheel(byte WheelPos) {
///TODO: Comment this stuff ///TODO: Comment this stuff
void setup() { void setup() {
Serial.begin(9600);
while(!Serial);
Serial.println("Starting Ethernet");
// Start Ethernet // Start Ethernet
Ethernet.begin(mac, ip); Ethernet.begin(mac, ip);
Serial.println("Ethernet Started");
// Set up webpages // Set up webpages
webserver.setDefaultCommand(&webSetSequence); webserver.setDefaultCommand(&webSetSequence);
webserver.addCommand("custom", &webSetSequence); webserver.addCommand("custom", &webSetSequence);
...@@ -430,29 +444,38 @@ void loop() ...@@ -430,29 +444,38 @@ void loop()
char buff[64]; char buff[64];
int len = 64; int len = 64;
webserver.processConnection(buff, &len); webserver.processConnection(buff, &len);
if (position > 255) {
position = position % 256;
if (lightOption != 0) {
lightOption++;
}
}
if (lightOption > NUMSEQUENCES) { if (lightOption > NUMSEQUENCES) {
lightOption = 1; //lightOption = 1;
} }
// Run our light sequence after checking for we requests // Run our light sequence after checking for we requests
///TODO: Make these switches nicer ///TODO: Make these switches nicer
switch (lightOption) { switch (lightOption) {
case 0: // Don't change the lights at all case 0: // Don't change the lights at all
lightOption = 2;
break; break;
case 1: // Wipe the LED's to Red case 1: // Wipe the LED's to Red
colourWipe(strip.Color(red, green, blue), 50); // Red colourWipe(strip.Color(red, green, blue), 50);
Serial.println("ColourWipe");
break; break;
case 2: case 2:
rainbow(20);
Serial.println("Rainbow");
break;
case 3:
rainbowCycle(20);
Serial.println("RainbowCycle");
break;
case 4:
theaterChaseRainbow(20);
Serial.println("TheaterChaseRainbow");
break;
default: default:
lightOption = 1; lightOption = 1;
break; break;
} }
// Show our lights // Show our lights
updateLights(); if (position == 0) { // if we have completed a sequence, move to the next one
lightOption++;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment