in individual sketches but I was hoping I could get a number of different effects in one
sketch that I could trigger each one using serial inputs.
I've seen some examples where button presses etc. will trigger various sections of a sketch
but I don't seem to be able to get anything working other than the simplest of effects.
I have this script working but I'd love to get a smooth flowing rainbow effect added to it:
- Code: Select all
#include "LPD8806.h"
#include "SPI.h"
int dataPin = 2;
int clockPin = 3;
const int numPixels = 160;
LPD8806 strip = LPD8806(160, dataPin, clockPin);
void setup() {
strip.begin();
strip.show();
Serial.begin(9600);
}
// function prototypes, do not remove these!
void colorChase(uint32_t c, uint8_t wait);
void colorWipe(uint32_t c, uint8_t wait);
void dither(uint32_t c, uint8_t wait);
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
void wave(uint32_t c, int cycles, uint8_t wait);
void rainbowCycle(uint8_t wait);
uint32_t Wheel(uint16_t WheelPos);
void loop() {
// read the sensor:
if (Serial.available() > 0) {
char inByte = Serial.read();
Serial.print("Command Received ");
Serial.print(inByte);
Serial.print("\n\r");
int i;
uint32_t c;
switch (inByte) {
case 'a':
while (!Serial.available()) {
// Set all pixels to red
c = strip.Color(255,0,0);
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
delay(100);
}
break;
case 'b':
while (!Serial.available()) {
// Wipe from middle:
c = strip.Color(255,255,255); // white
for (i=strip.numPixels() / 2 - 1; i >= 0; i--) { // half of strip, count down to 0
strip.setPixelColor(i, c); // left pixel
strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
strip.show();
delay(100);
}
break;
case 'c':
while (!Serial.available()) {
digitalWrite(13, HIGH); // set the LED on
delay(150); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(150); // wait for a second
}
break;
case 'd':
while (!Serial.available()) {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
break;
case 'e':
while (!Serial.available()) {
digitalWrite(13, LOW); // set the LED off
delay(20); // wait for a second
}
break;
default:
// turn all the LEDs off:
for (int thisPin = 13; thisPin < 13; thisPin++) {
digitalWrite(thisPin, LOW);
}
}
}
}
}
When I copy code from another script and paste it into the section with the break I can never
get it to compile. Any pointers on inserting effects into the break areas would be greatly appreciated!
Thanks,
Carl

