I am trying to setup a LPD8806 RGB light strip to run different sequences at differences
I am using a sketch that I found for running a piezo speaker to sound at different distances and different hrz along with the advanced led belt kit.
I have been abe to get both of them working indepently but have not been able to combine them.
- Code: Select all
#include <avr/pgmspace.h>
#include "SPI.h"
#include "LPD8806.h"
#include "TimerOne.h"
#if defined(USB_SERIAL) || defined(USB_SERIAL_ADAFRUIT)
// this is for teensyduino support
int dataPin = 2;
int clockPin = 1;
#else
// these are the pins we use for the LED belt kit using
// the Leonardo pinouts
int dataPin = 16;
int clockPin = 15;
#endif
int sonarPin = 0; //pin connected to analog out on maxsonar sensor
int piezoPin = 9; // specifies the pin connected to piezo from Arduino
int inchesAway; // inches away from the maxsonar sensor
// Declare the number of pixels in strand; 32 = 32 pixels in a row. The
// LED strips have 32 LEDs per meter, but you can extend or cut the strip.
const int numPixels = 32;
// 'const' makes subsequent array declarations possible, otherwise there
// would be a pile of malloc() calls later.
// Instantiate LED strip; arguments are the total number of pixels in strip,
// the data pin number and clock pin number:
LPD8806 strip = LPD8806(numPixels, dataPin, clockPin);
// You can also use hardware SPI for ultra-fast writes by omitting the data
// and clock pin arguments. This is faster, but the data and clock are then
// fixed to very specific pin numbers: on Arduino 168/328, data = pin 11,
// clock = pin 13. On Mega, data = pin 51, clock = pin 52.
//LPD8806 strip = LPD8806(numPixels);
// Principle of operation: at any given time, the LEDs depict an image or
// animation effect (referred to as the "back" image throughout this code).
// Periodically, a transition to a new image or animation effect (referred
// to as the "front" image) occurs. During this transition, a third buffer
// (the "alpha channel") determines how the front and back images are
// combined; it represents the opacity of the front image. When the
// transition completes, the "front" then becomes the "back," a new front
// is chosen, and the process repeats.
byte imgData[2][numPixels * 3], // Data for 2 strips worth of imagery
alphaMask[numPixels], // Alpha channel for compositing images
backImgIdx = 0, // Index of 'back' image (always 0 or 1)
fxIdx[3]; // Effect # for back & front images + alpha
int fxVars[3][50], // Effect instance variables (explained later)
tCounter = -1, // Countdown to next transition
transitionTime; // Duration (in frames) of current transition
// function prototypes, leave these be :)
void renderEffect00(byte idx);
void renderEffect01(byte idx);
void renderEffect02(byte idx);
void renderEffect03(byte idx);
void renderAlpha00(void);
void renderAlpha01(void);
void renderAlpha02(void);
void renderAlpha03(void);
void callback();
byte gamma(byte x);
long hsv2rgb(long h, byte s, byte v);
char fixSin(int angle);
char fixCos(int angle);
// List of image effect and alpha channel rendering functions; the code for
// each of these appears later in this file. Just a few to start with...
// simply append new ones to the appropriate list here:
void (*renderEffect[])(byte) = {
renderEffect00,
renderEffect01,
renderEffect02,
renderEffect03 },
(*renderAlpha[])(void) = {
renderAlpha00,
renderAlpha01,
renderAlpha02 };
// ---------------------------------------------------------------------------
void setup() {
pinMode(piezoPin, OUTPUT);
//Serial.begin(9600); // starts serial communication, used for debugging or seeing the values
// Start up the LED strip. Note that strip.show() is NOT called here --
// the callback function will be invoked immediately when attached, and
// the first thing the calback does is update the strip.
strip.begin();
// Initialize random number generator from a floating analog input.
randomSeed(analogRead(0));
memset(imgData, 0, sizeof(imgData)); // Clear image data
fxVars[backImgIdx][0] = 1; // Mark back image as initialized
// Timer1 is used so the strip will update at a known fixed frame rate.
// Each effect rendering function varies in processing complexity, so
// the timer allows smooth transitions between effects (otherwise the
// effects and transitions would jump around in speed...not attractive).
Timer1.initialize();
Timer1.attachInterrupt(callback, 1000000 / 60); // 60 frames/second
}
void loop() {
}
void callback() {
inchesAway = analogRead(sonarPin) /2; // reads the maxsonar sensor and divides the value by 2
// approximate distance in inches
//Serial.print(inchesAway); // prints the sensor information from the maxsonar to the serial monitor
//Serial.println(" inches from sensor");
if (inchesAway < 24) { // if something is 24 inches away then make a 1khz sound
digitalWrite(piezoPin, HIGH);
delayMicroseconds(500);
digitalWrite(piezoPin, LOW);
delayMicroseconds(500);
}
if (inchesAway < 10) { // if something is 10 inches away then make a 1khz sound
digitalWrite(piezoPin, HIGH);
delayMicroseconds(1000);
digitalWrite(piezoPin, LOW);
delayMicroseconds(1000);
}
}
This is what i have so far.
Once I start adding any of the void functions such as
- Code: Select all
void renderEffect00(byte idx) {
// Only needs to be rendered once, when effect is initialized:
if(fxVars[idx][0] == 0) {
byte *ptr = &imgData[idx][0],
r = random(256), g = random(256), b = random(256);
for(int i=0; i<numPixels; i++) {
*ptr++ = r; *ptr++ = g; *ptr++ = b;
}
fxVars[idx][0] = 1; // Effect initialized
}
}
I get an error - a function-definition is not allowed here before '{' token
Please let me know if I can provide any other info that might help aid in answering the question
thanks

