Having Trouble Converting Code

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jm4355
 
Posts: 2
Joined: Sun Aug 31, 2014 5:39 pm

Having Trouble Converting Code

Post by jm4355 »

All-

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);
      }
    }
 
  }
 
}
So my question is what am I doing wrong here?

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Having Trouble Converting Code

Post by Franklin97355 »

What do you get when you run your code?

User avatar
jm4355
 
Posts: 2
Joined: Sun Aug 31, 2014 5:39 pm

Re: Having Trouble Converting Code

Post by jm4355 »

When I run the code on the arduino I only get the first 4 LEDs lighting up very dimly and the rest of the 2m is completely dark.

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Having Trouble Converting Code

Post by Franklin97355 »


Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”