I am looking to convert this coding that I was able to find online here ( http://www.open-electronics.org/big-spe ... h-arduino/ ) into code that would be accepted by the LPD8806 LED Strip. A little background on my project, I have 2m of the LPD8806 LED Strips wired in series with a 5v 4a power supply from adafruit. I am running an arduino uno with the sparkfun spectrum shield ( https://www.sparkfun.com/products/10306 ). I have done very little programming as a whole but I do have a rudimentary background in java based programming.
This is my best attempt at converting the code over using my extremely limited knowledge of C++ and other peoples code. Any help you could provide I would really appreciate it.
Code: Select all
#include "LPD8806.h"
#include "SPI.h"
int nLEDs = 48;
int length=8;
// Chose 2 pins for output; can be any valid output pins:
int dataPin = 2;
int clockPin = 3;
int strobe = 4; // strobe pins on digital 4
int res = 5; // reset pins on digital 5
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);
//the bar is divided into three parts
int colorbar1_3=strip.Color(0,127, 0); //GREEN
int colorbar2_3=strip.Color( 255, 255, 0); //YELLOW;
int colorbar3_3=strip.Color(157, 0, 255); //Purple
int colorstart=strip.Color(0,127, 0);
int colorend=strip.Color(157, 0, 255);
int sect1=2; //end point of the first section of the strip
int sect2=4; //end point of the first section of the strip and beginning of the third
boolean bar=1;
boolean pointend=0;
boolean pointstart=0;
unsigned int Divisor = 70, ChangeTimer=0; //, ReminderDivisor,
int left[7]; // store band values in these arrays
int band;
// First parameter is the number of LEDs in the strand. The LED strips
// are 32 LEDs per meter but you can extend or cut the strip. Next two
// parameters are SPI data and clock pins:
void setup() {
// Start up the LED strip
strip.begin();
// Update the strip, to start they are all 'off'
strip.show();
}
void readMSGEQ7() {
// Function to read 7 band equalizers
digitalWrite(res, HIGH);
digitalWrite(res, LOW);
for(band=0; band <7; band++) {
digitalWrite(strobe,LOW); // strobe pin on the shield - kicks the IC up to the next band
delayMicroseconds(30); //
left[band] = analogRead(0); // store left band reading
digitalWrite(strobe,HIGH);
}
}
void loop() {
showSpectrum();
}
void showSpectrum()
{
readMSGEQ7();
byte Band, BarSize, MaxLevel;
unsigned int works, Remainder;
MaxLevel = 0;
for(Band=0;Band<7;Band++)//We only graph the lowest 5 bands here, there is 2 more unused!
{
works = left[Band]/Divisor; //Bands are read in as 10 bit values. Scale them down to be 0 - 5
if(works > MaxLevel) //Check if this value is the largest so far.
MaxLevel = works;
colorWipe(Band,works);
}
strip.show();
// Adjust the Divisor if levels are too high/low. AGC
if (MaxLevel >= (length-1))
{
Divisor=Divisor+1;
ChangeTimer=0;
}
else
if(MaxLevel < (sect2))
{
if(Divisor > 50)
if(ChangeTimer++ > 20)
{
Divisor--;
ChangeTimer=0;
}
}
else
{
ChangeTimer=0;
}
}
void colorWipe(uint8_t Band, uint8_t works) {
uint8_t i;
int inizio=Band*(length);
int fine =inizio+length-1;
for (i=inizio; i < (fine); i++) {
strip.setPixelColor(i,strip.Color(0,0,0));
}
if (Band==0 || Band==2 || Band==4 || Band==6){
if (pointstart==0) {
inizio--;
}
else
{
strip.setPixelColor(inizio, colorstart);
}
if (bar==1){
for (i=inizio+1; i < (inizio +works); i++) {
if ((i-inizio) <=sect1) strip.setPixelColor(i, colorbar1_3);
if ((i-inizio) >sect1 &&(i-inizio) <=sect2) strip.setPixelColor(i, colorbar2_3);
if ((i-inizio) >sect2 ) strip.setPixelColor(i, colorbar3_3);
}
}
if (pointend==1) strip.setPixelColor((inizio +works), colorend);
}
else
{
if (pointstart==0) {
fine++;
}
else
{
strip.setPixelColor(fine, colorstart);
}
if (pointend==1) strip.setPixelColor((fine-works-1), colorend);
if (bar==1){
for (i=(fine-works); i < fine; i++) {
if ((fine-i) <=sect1) strip.setPixelColor(i, colorbar1_3);
if ((fine-i) >sect1 &&(fine-i) <=sect2) strip.setPixelColor(i, colorbar2_3);
if ((fine-i) >sect2 ) strip.setPixelColor(i, colorbar3_3);
}
}
}
}