Pages: [1]   Go Down
Author Topic: Little Help Streamlining My MSGEQ7 LED Spectrum Analyzer Code (Solved) Thanks!  (Read 1076 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ive managed to make a basic Spectrum Analyer using an MSGEQ7 chip and 3x 74hc595 shift registers.

At the moment Im only displaying 3 of the frequencies of the 7 possible. Each Frequency goes to its own shift register that is linked to 8 LEDs. The more leds that are lit the higher the output of that particular frequency.
  
The code works and can be expanded upon to use more shift registers and the plan is to do exactly that. Ive ordered lots more and the plan is to run 2x MSGEQ7, 1 per channel, displaying all 7 frequencies for each channel and perhaps another per channel displaying the over all output of said channel = 16 columns of LEDs, 8+ LEDs high(perhaps 16 high).
 
Heres the Code:
Code:
#include <Shifter.h>
int analogPin = 0; // read from multiplexer using analog input 0
int strobePin = 2; // strobe is attached to digital pin 2
int resetPin = 4; // reset is attached to digital pin 3
int spectrumValue[7]; // to hold a2d values
#define SER_Pin 8 //SER_IN
#define RCLK_Pin 9 //L_CLOCK
#define SRCLK_Pin 10 //CLOCK

#define NUM_REGISTERS 3 //how many registers are in the chain


//initaize shifter using the Shifter library
Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);

void setup(){
 Serial.begin(9600);
 pinMode(strobePin, OUTPUT);
  pinMode(resetPin, OUTPUT);
  analogReference(DEFAULT);

  digitalWrite(resetPin, LOW);
  digitalWrite(strobePin, HIGH);
  delayMicroseconds(100);
 
}

void loop(){
   digitalWrite(resetPin, HIGH);
  digitalWrite(resetPin, LOW);

  for (int i = 0; i < 7; i++)
  {
    digitalWrite(strobePin, LOW);
    delayMicroseconds(35); // to allow the output to settle
    spectrumValue[i] = analogRead(analogPin);

    //comment out/remove the serial stuff to go faster
    // - its just here for show
  /*  if (spectrumValue[i] < 10)
    {
      Serial.print("    ");
      Serial.print(spectrumValue[i]);
    }
    else if (spectrumValue[i] < 100 )
    {
      Serial.print("   ");
      Serial.print(spectrumValue[i]);
    }
    else
    {
      Serial.print("  ");
      Serial.print(spectrumValue[i]);
 }
    */  
    digitalWrite(strobePin, HIGH);
  }
  
shifter.clear(); //set all pins on the shift register chain to LOW
shifter.write(); //send changes to the chain and display them
  
    if (spectrumValue[1] >= 65 && spectrumValue[1] <= 1023){
      shifter.setPin(0, HIGH);}
        else {shifter.setPin(0, LOW);}

    if (spectrumValue[1] >= 185 && spectrumValue[1] <= 1023){
      shifter.setPin(1, HIGH);}
else {shifter.setPin(1, LOW);}

    if (spectrumValue[1] >= 300 && spectrumValue[1] <= 1023){
      shifter.setPin(2, HIGH);}

else {shifter.setPin(2, LOW);}  

if (spectrumValue[1] >= 415 && spectrumValue[1] <= 1023){
      shifter.setPin(3, HIGH);}
else {shifter.setPin(3, LOW);}  

if (spectrumValue[1] >= 530 && spectrumValue[1] <= 1023){
      shifter.setPin(4, HIGH);}
else {shifter.setPin(4, LOW);}

if (spectrumValue[1] >= 645 && spectrumValue[1] <= 1023){
      shifter.setPin(5, HIGH);}
else {shifter.setPin(5, LOW);}

if (spectrumValue[1] >= 760 && spectrumValue[1] <= 1023){
      shifter.setPin(6, HIGH);}
else {shifter.setPin(6, LOW);}

if (spectrumValue[1] >= 875 && spectrumValue[1] <= 1023){
      shifter.setPin(7, HIGH);}
else {shifter.setPin(7, LOW);}

    if (spectrumValue[3] >= 65 && spectrumValue[3] <= 1023){
      shifter.setPin(8, HIGH);}
else {shifter.setPin(8, LOW);}

    if (spectrumValue[3] >= 185 && spectrumValue[3] <= 1023){
      shifter.setPin(9, HIGH);}
else {shifter.setPin(9, LOW);}

    if (spectrumValue[3] >= 300 && spectrumValue[3] <= 1023){
      shifter.setPin(10, HIGH);}
else {shifter.setPin(10, LOW);}

if (spectrumValue[3] >= 415 && spectrumValue[3] <= 1023){
      shifter.setPin(11, HIGH);}
else {shifter.setPin(11, LOW);}

if (spectrumValue[3] >= 530 && spectrumValue[3] <= 1023){
      shifter.setPin(12, HIGH);}
else {shifter.setPin(12, LOW);}

if (spectrumValue[3] >= 645 && spectrumValue[3] <= 1023){
      shifter.setPin(13, HIGH);}
else {shifter.setPin(13, LOW);}

if (spectrumValue[3] >= 760 && spectrumValue[3] <= 1023){
      shifter.setPin(14, HIGH);}
else {shifter.setPin(14, LOW);}

if (spectrumValue[3] >= 875 && spectrumValue[3] <= 1023){
      shifter.setPin(15, HIGH);}
else {shifter.setPin(15, LOW);}

    if (spectrumValue[5] >= 75 && spectrumValue[5] <= 1023){
      shifter.setPin(16, HIGH);}
else {shifter.setPin(16, LOW);}

    if (spectrumValue[5] >= 185 && spectrumValue[5] <= 1023){
      shifter.setPin(17, HIGH);}
else {shifter.setPin(17, LOW);}

    if (spectrumValue[5] >= 300 && spectrumValue[5] <= 1023){
      shifter.setPin(18, HIGH);}
else {shifter.setPin(18, LOW);}

if (spectrumValue[5] >= 415 && spectrumValue[5] <= 1023){
      shifter.setPin(19, HIGH);}
else {shifter.setPin(19, LOW);}

if (spectrumValue[5] >= 530 && spectrumValue[5] <= 1023){
      shifter.setPin(20, HIGH);}
 else {shifter.setPin(20, LOW);}

if (spectrumValue[5] >= 645 && spectrumValue[5] <= 1023){
      shifter.setPin(21, HIGH);}
else {shifter.setPin(21, LOW);}

if (spectrumValue[5] >= 760 && spectrumValue[5] <= 1023){
      shifter.setPin(22, HIGH);}
else {shifter.setPin(22, LOW);}

if (spectrumValue[5] >= 875 && spectrumValue[5] <= 1023){
     shifter.setPin(23, HIGH);}
else {shifter.setPin(23, LOW);}
    
 // Serial.println();

shifter.write(); //send changes to the chain and display them
//notice how you only call write after you make all the changes you want to make

}

As you can see its a little bulky & would be 4 to 5x larger for 16 frequencies. So Ive been trying to work out how I can turn this part into a Function so that it only has to be written once and just fed a couple of variables.

Code:
 
// Shift Register 1  
  
    if (spectrumValue[1] >= 65 && spectrumValue[1] <= 1023){
      shifter.setPin(0, HIGH);}
        else {shifter.setPin(0, LOW);}

    if (spectrumValue[1] >= 185 && spectrumValue[1] <= 1023){
      shifter.setPin(1, HIGH);}
else {shifter.setPin(1, LOW);}

    if (spectrumValue[1] >= 300 && spectrumValue[1] <= 1023){
      shifter.setPin(2, HIGH);}

else {shifter.setPin(2, LOW);}  

if (spectrumValue[1] >= 415 && spectrumValue[1] <= 1023){
      shifter.setPin(3, HIGH);}
else {shifter.setPin(3, LOW);}  

if (spectrumValue[1] >= 530 && spectrumValue[1] <= 1023){
      shifter.setPin(4, HIGH);}
else {shifter.setPin(4, LOW);}

if (spectrumValue[1] >= 645 && spectrumValue[1] <= 1023){
      shifter.setPin(5, HIGH);}
else {shifter.setPin(5, LOW);}

if (spectrumValue[1] >= 760 && spectrumValue[1] <= 1023){
      shifter.setPin(6, HIGH);}
else {shifter.setPin(6, LOW);}

if (spectrumValue[1] >= 875 && spectrumValue[1] <= 1023){
      shifter.setPin(7, HIGH);}
else {shifter.setPin(7, LOW);}

// Shift Register 2

    if (spectrumValue[3] >= 65 && spectrumValue[3] <= 1023){
      shifter.setPin(8, HIGH);}
else {shifter.setPin(8, LOW);}

    if (spectrumValue[3] >= 185 && spectrumValue[3] <= 1023){
      shifter.setPin(9, HIGH);}
else {shifter.setPin(9, LOW);}

    if (spectrumValue[3] >= 300 && spectrumValue[3] <= 1023){
      shifter.setPin(10, HIGH);}
else {shifter.setPin(10, LOW);}

if (spectrumValue[3] >= 415 && spectrumValue[3] <= 1023){
      shifter.setPin(11, HIGH);}
else {shifter.setPin(11, LOW);}

if (spectrumValue[3] >= 530 && spectrumValue[3] <= 1023){
      shifter.setPin(12, HIGH);}
else {shifter.setPin(12, LOW);}

if (spectrumValue[3] >= 645 && spectrumValue[3] <= 1023){
      shifter.setPin(13, HIGH);}
else {shifter.setPin(13, LOW);}

if (spectrumValue[3] >= 760 && spectrumValue[3] <= 1023){
      shifter.setPin(14, HIGH);}
else {shifter.setPin(14, LOW);}

if (spectrumValue[3] >= 875 && spectrumValue[3] <= 1023){
      shifter.setPin(15, HIGH);}
else {shifter.setPin(15, LOW);}

//Shift Register 3

    if (spectrumValue[5] >= 75 && spectrumValue[5] <= 1023){
      shifter.setPin(16, HIGH);}
else {shifter.setPin(16, LOW);}

    if (spectrumValue[5] >= 185 && spectrumValue[5] <= 1023){
      shifter.setPin(17, HIGH);}
else {shifter.setPin(17, LOW);}

    if (spectrumValue[5] >= 300 && spectrumValue[5] <= 1023){
      shifter.setPin(18, HIGH);}
else {shifter.setPin(18, LOW);}

if (spectrumValue[5] >= 415 && spectrumValue[5] <= 1023){
      shifter.setPin(19, HIGH);}
else {shifter.setPin(19, LOW);}

if (spectrumValue[5] >= 530 && spectrumValue[5] <= 1023){
      shifter.setPin(20, HIGH);}
 else {shifter.setPin(20, LOW);}

if (spectrumValue[5] >= 645 && spectrumValue[5] <= 1023){
      shifter.setPin(21, HIGH);}
else {shifter.setPin(21, LOW);}

if (spectrumValue[5] >= 760 && spectrumValue[5] <= 1023){
      shifter.setPin(22, HIGH);}
else {shifter.setPin(22, LOW);}

if (spectrumValue[5] >= 875 && spectrumValue[5] <= 1023){
     shifter.setPin(23, HIGH);}
else {shifter.setPin(23, LOW);}

But Im a little stuck, Ive never created a function before smiley

« Last Edit: December 08, 2011, 01:52:10 pm by p00ky » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As the spectrumValue and the shift registers setPin (output Pin) are set incrementaly Im confused how to even begin let alone on how to call the function in the void loop.

 Youve probably noticed it also uses a 3rd party Shift Register Library I got from

 http://bildr.org/2011/08/74hc595-breakout-arduino/

Which has complicated things again as thats where the shift register pins are set based on the no. of shift registers used.

The library code is (its open source)

Shifter.h
Code:
#ifndef Shifter_h
#define Shifter_h

// Include the standard types
#include <Arduino.h>

// Define the Shifter class
class Shifter
{
  public:
    // Constructor
    Shifter(int SER_Pin, int RCLK_Pin, int SRCLK_Pin, int Number_of_Registers);
   void write();
   void setPin(int index, boolean val);
   void setAll(boolean val);
   void clear();



  private:
int _SER_Pin;
   int _RCLK_Pin;
   int _SRCLK_Pin;
   int _Number_of_Registers;
   byte _shiftRegisters[25];
};

#endif //Shifter_h

&
Shifter.cpp
Code:
// Include the standard types
#include <Arduino.h>
#include <Shifter.h>


// Constructor
Shifter::Shifter(int SER_Pin, int RCLK_Pin, int SRCLK_Pin, int Number_of_Registers){
_SER_Pin = SER_Pin;
_RCLK_Pin = RCLK_Pin;
_SRCLK_Pin = SRCLK_Pin;

_Number_of_Registers = Number_of_Registers;


pinMode(_SER_Pin, OUTPUT);
pinMode(_RCLK_Pin, OUTPUT);
pinMode(_SRCLK_Pin, OUTPUT);


clear(); //reset all register pins
write();
}

void Shifter::write(){
//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)

  digitalWrite(_RCLK_Pin, LOW);
 
  //iterate through the registers
  for(int i = _Number_of_Registers - 1; i >=  0; i--){
   
    //iterate through the bits in each registers
    for(int j = 8 - 1; j >=  0; j--){
     
      digitalWrite(_SRCLK_Pin, LOW);   
     
      int val = _shiftRegisters[i] & (1 << j);
     
      digitalWrite(_SER_Pin, val);
      digitalWrite(_SRCLK_Pin, HIGH);
   
    }
   
  }
 
  digitalWrite(_RCLK_Pin, HIGH);
}

void Shifter::setPin(int index, boolean val){
int byteIndex = index/8;
int bitIndex = index % 8;

byte current = _shiftRegisters[byteIndex];

current &= ~(1 << bitIndex); //clear the bit
current |= val << bitIndex; //set the bit

_shiftRegisters[byteIndex] = current; //set the value
}

void Shifter::setAll(boolean val){
//set all register pins to LOW 
  for(int i = _Number_of_Registers * 8 - 1; i >=  0; i--){
     setPin(i, val);
  }
}


void Shifter::clear(){
//set all register pins to LOW 
  for(int i = _Number_of_Registers * 8 - 1; i >=  0; i--){
     setPin(i, LOW);
  }
}

As Im a hopeless beginner any and all hints and tips are greatly appreciated. Im sure there are much more elegant solutions to this smiley

Anyways, Thanks in advance .
« Last Edit: December 08, 2011, 09:05:44 am by p00ky » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    spectrumValue[i] = analogRead(analogPin);
By definition, spectrumValue elements can not contain values greater than 1023.

So,
Code:
    if (spectrumValue[1] >= 65 && spectrumValue[1] <= 1023){
it is not necessary to affirm that the value is less than or equal 1023.

Your breakpoints for activating a particular pin are 65, 185, 300, 415, 530, 645, 760, and 875. The increment from one value to the next is 65, 120, 115, 115, 115, 115, 115, and 115. If you were willing to turn the 1st pin on at 70, instead of 65,  you would have increments of 70, 115, 115, 115, 115, 115, 115, and 115. If you did that, you could add 45 to the value in spectrumValue[n], and divide by 115 to get the number of pins to activate.

If spectrumValue contained 70, adding 45 would make it 115. Dividing by 115 would give 1. Any value smaller than 70 would result in 0.

If spectumValue[n] contained 1023, adding 45 would make it 1068. Dividing that by 115 would give 9. That is more pins than you have, so you'd simply activate all of them.

Once you know how many to set HIGH, loop through all the pins, and set the first n HIGH, and the rest low.

Code:
void setPins(Shifter &shifter, int spectrumValue)
{
   int highPinCnt = (spectrumValue+45)/115;
   for(int i=0; i<8; i++)
   {
      if(i<=highPinCnt)
        shifter.setPin(i, HIGH);
      else
        shifter.setPin(i, LOW);
   }
}

Then, you'd call this function:
Code:
  setPins(shifter, spectrumValue[1]);

When you create more Shifter instances:
Code:
Shifter shifter1(SER_Pin1, RCLK_Pin1, SRCLK_Pin1, NUM_REGISTERS);
Shifter shifter2(SER_Pin2, RCLK_Pin2, SRCLK_Pin2, NUM_REGISTERS);

you could then call the function like so:
Code:
  setPins(shifter1, spectrumValue[1]);
  setPins(shifter2, spectrumValue[3]);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for getting back to me so quickly, all help is appreciated muchly.

So firstly I implemented your first suggestion (removal of the "&& <= 1024) as it wasnt required. This worked perfectly.

Secondly I changed the base activation no. from 65 to 70. I had just been mucking around with no.s here. The selection of 65 was just enough to cut out a reading from the background hum so upping it to 70 was no biggy & this obviously worked fine.

My troubles came when trying to implement this scaling to the function "void setPins".

I firstly implemented with a single frequency

Code:
#include <Shifter.h>
int analogPin = 0; // read from multiplexer using analog input 0
int strobePin = 2; // strobe is attached to digital pin 2
int resetPin = 4; // reset is attached to digital pin 3
int spectrumValue[7]; // to hold a2d values
#define SER_Pin 8 //SER_IN
#define RCLK_Pin 9 //L_CLOCK
#define SRCLK_Pin 10 //CLOCK

#define NUM_REGISTERS 3 //how many registers are in the chain


//initaize shifter using the Shifter library
Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);


void setup(){
 Serial.begin(9600);
 pinMode(strobePin, OUTPUT);
  pinMode(resetPin, OUTPUT);
  analogReference(DEFAULT);

  digitalWrite(resetPin, LOW);
  digitalWrite(strobePin, HIGH);
  delayMicroseconds(100);
 
}

void loop(){
   digitalWrite(resetPin, HIGH);
  digitalWrite(resetPin, LOW);

  for (int i = 0; i < 7; i++)
  {
    digitalWrite(strobePin, LOW);
    delayMicroseconds(35); // to allow the output to settle
    spectrumValue[i] = analogRead(analogPin);

    //comment out/remove the serial stuff to go faster
    // - its just here for show
  /*  if (spectrumValue[i] < 10)
    {
      Serial.print("    ");
      Serial.print(spectrumValue[i]);
    }
    else if (spectrumValue[i] < 100 )
    {
      Serial.print("   ");
      Serial.print(spectrumValue[i]);
    }
    else
    {
      Serial.print("  ");
      Serial.print(spectrumValue[i]);
 }
    */   
    digitalWrite(strobePin, HIGH);
  }
 
//shifter.clear(); //set all pins on the shift register chain to LOW
//shifter.write(); //send changes to the chain and display them
   
 setPins(shifter, spectrumValue[1]);

     
 // Serial.println();

shifter.write(); //send changes to the chain and display them
//notice how you only call write after you make all the changes you want to make

}

void setPins(Shifter &shifter, int spectrumValue)
{
   int highPinCnt = (spectrumValue+45)/115;
   for(int i=0; i<8; i++)
   {
      if(i<=highPinCnt)
        shifter.setPin(i, HIGH);
      else
        shifter.setPin(i, LOW);
   }
}

This worked fine, displaying "spectrumValue[1]" on the first shift register. But when i added

Code:
Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);
Shifter shifter1(SER_Pin1, RCLK_Pin1, SRCLK_Pin1, NUM_REGISTERS);
Shifter shifter2(SER_Pin2, RCLK_Pin2, SRCLK_Pin2, NUM_REGISTERS);

Calling it with

Code:
setPins(shifter, spectrumValue[1]);
setPins(shifter1, spectrumValue[3]);
setPins(shifter2, spectrumValue[5]);

I got the compiling error

"MsgEq7ShiftRegisterLibraryMODIFIED2:14: error: 'SER_Pin1' was not declared in this scope
MsgEq7ShiftRegisterLibraryMODIFIED2:14: error: 'RCLK_Pin1' was not declared in this scope
MsgEq7ShiftRegisterLibraryMODIFIED2:14: error: 'SRCLK_Pin1' was not declared in this scope
MsgEq7ShiftRegisterLibraryMODIFIED2:15: error: 'SER_Pin2' was not declared in this scope
MsgEq7ShiftRegisterLibraryMODIFIED2:15: error: 'RCLK_Pin2' was not declared in this scope
MsgEq7ShiftRegisterLibraryMODIFIED2:15: error: 'SRCLK_Pin2' was not declared in this scope"

I assume this is because the code assumes that each shift register is individually programmed and latched by differant pins on the arduino & that these pins have not been defined.

However my shift registers are daisy chained, therefore they use the same pins. So changing the code to
Code:
Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);
Shifter shifter1(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);
Shifter shifter2(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);
had no effect.

As far as i can see i need another way to define  "shifter", "shifter1", "shifter2" etc. Or another way to  allocate "setPins" that is not based on "shifter
  • ".

It seems odd that the library doesnt give you the power to call on a certain Pin on a certain shift register (perhaps its does?) just individual pins. eg

setPin(20, HIGH);
& not
setPin(Shifter2, Pin5, HIGH);  //shifter2 being the third shift register (shifter, shifter1, shifter2, etc)

thanks again for the help



Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You only need one shifter instance. What you need to define is which pins the setPins() function is to modify.

Code:
void setPins(Shifter &shifter, int spectrumValue, int pinOffset)
{
   int highPinCnt = (spectrumValue+45)/115;
   for(int i=0; i<8; i++)
   {
      if(i<=highPinCnt)
        shifter.setPin(i+pinOffset, HIGH);
      else
        shifter.setPin(i+pinOffset, LOW);
   }
}

Then, call it:
Code:
setPins(shifter, spectrumValue[1], 0); // Sets pins 0 to 7
 setPins(shifter, spectrumValue[3], 8); // Sets pins 8 to 15
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah!

 i+pinOffset

I see, that certainly worked and will be simple to implement when it comes to my expansion plans.

There is only 1 problem smiley its not a biggy but...

The bottem LED for each Frequency is now always on, there is no cut off for spectrumValues < 70
I tryed modifiying the no.s in
Code:
int highPinCnt = (spectrumValue+45)/115;
But that didnt seem to help, lowering the spectrumValue infact increased the no. of LEDs that were on by default, all other changes had little to no effect at all.
I also tryed
Code:
if(i<=highPinCnt)
        shifter.setPin(i+pinOffset, HIGH);
if(spectrumValue <=70)
        shifter.setPin(i+pinOffset, LOW);
      else
        shifter.setPin(i+pinOffset, LOW);

But it didnt like that at all, all LEDs were off smiley

Sorry, if its any consellation, I am becoming aware of how little i know smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I added into void setPins

Code:
if(highPinCnt <1)
  shifter.setPin(i+pinOffset, LOW);

which gave me a cut off bellow 70, but of course now the bottem 2 Leds display the same frequency level.

I guess I need to  make
Code:
for(int i=0; i<8; i++)
only happen if
Code:
if(highPinCnt >1)
*EDIT
Just tryed that
Code:
void setPins(Shifter &shifter, int spectrumValue, int pinOffset)
{
   int highPinCnt = (spectrumValue+45)/115;
   if(highPinCnt >=1){
   for(int i=0; i<8; i++)
   {
      if(i<=highPinCnt)
        shifter.setPin(i+pinOffset, HIGH);
      else
        shifter.setPin(i+pinOffset, LOW);

   }
}
}
But this gives me the same as before, the bottem 2 leds displaying the same frequency. Im sure im close tho smiley
« Last Edit: December 08, 2011, 11:14:09 am by p00ky » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Add some Serial.print() statements to setPins() to show the spectrumValue and highPinCnt.

When spectrumValue is less than 70, highPinCnt should equal 0.

The if(i<=highPinCnt) should be if(i<highPinCnt).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hehehe smiley

Thanks for pointing out the "=" that shouldnt have been there. That solved it completly. Ive spent the last 8 hours fiddling with the sums, subtracts from "i", adding to "i" declaring int j=i-1 then setting pin(j) but to no avail.

 I do love hobbies that make you feel stupid & then remind you of it at every given opppotunity.

Electronics, a lesson in humility smiley

Thanks for all your help, lets just hope ive learned something from it.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I do love hobbies that make you feel stupid & then remind you of it at every given opppotunity.
That is too funny.
Logged

Pages: [1]   Go Up
Jump to: