spectrum shield

48 views
Skip to first unread message

Chris

unread,
Aug 26, 2012, 11:29:38 PM8/26/12
to toasted-circu...@googlegroups.com
Hi Andrew,

I also recently got the lightuino and a spectrum shield in the mail and am attempting a really simple project. Just getting a bunch of LEDs to have their brightness controlled according to the amplitude of the signal in its respective frequency band. Before using the lightuino, I made a smaller version, using only 6 LEDs on an arduino uno. My code for that is here:

int spectrumStrobe = 4;
int spectrumReset = 5;
int spectrumAnalog = A0;
int spectrum[7];

void setup()
{
  Serial.begin(9600);
  pinMode(spectrumAnalog, INPUT);
  pinMode(spectrumReset, OUTPUT);
  pinMode(spectrumStrobe, OUTPUT);
  analogReference(DEFAULT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(3, OUTPUT);
  digitalWrite(spectrumReset, LOW);
  digitalWrite(spectrumStrobe, HIGH);
}

void loop()
{
  digitalWrite(spectrumReset, HIGH);
  digitalWrite(spectrumReset, LOW);
  for(int i=0; i<7; i++)
  {
    digitalWrite(spectrumStrobe, HIGH);
    digitalWrite(spectrumStrobe, LOW);
    Serial.println(analogRead(spectrumAnalog));
    delay(3);
    spectrum[i] = analogRead(spectrumAnalog) / 4;
  }
  if(spectrum[0] > 15)
  {
    analogWrite(11, spectrum[0]);
  }
  else
  {
    analogWrite(11, 0);
  }
  if(spectrum[1] > 18)
  {
    analogWrite(10, spectrum[1]);
  }
  else
  {
    analogWrite(10, 0);
  }
  if(spectrum[2] > 15)
  {
    analogWrite(9, spectrum[2]);
  }
  else
  {
    analogWrite(9, 0);
  }
  if(spectrum[3] > 15)
  {
    analogWrite(6, spectrum[3]);
  }
  else
  {
    analogWrite(6, 0);
  }
  if(spectrum[4] > 15)
  {
    analogWrite(5, spectrum[4]);
  }
  else
  {
    analogWrite(5, 0);
  }
  if(spectrum[5] > 15)
  {
    analogWrite(3, spectrum[5]);
  }
  else
  {
    analogWrite(3, 0);
  }
}

It took me just a few minutes to write this and get this up and running. I am somewhat of a noob, so when I looked at your begin_here code I was completely confused and have since then stared at that code for hours, read forums, etc., and really figured out very little (so I haven't even gotten to the point of trying to hook up the shield yet). To be honest, I am not even really clear on how your code works at all since it was my understanding that you need have a section that is within a loop(){ } for any arduino code to work. Such is the level of my ignorance, and for that I apologize. Would you please send me in the right direction and try to help me find a lightuino solution for the above simple code? The reason why I needed the lightuino is because although I will still only be using 6 frequency bands, I want several LEDs per frequency band, like 8 or something, so needed more outputs.

I think you mentioned that you don't have a spectrum shield, so I don't really need specifics, but basically just need to figure out how to make a sketch where I can input pwm values that give brightnesses for the LEDs. Once I have that, I believe I will be able to get the shield working using similar code to the above and referring to the previous posts about the spectrum shield.

Thanks a lot for your patience with someone as new as me.

Chris

Andrew Stone

unread,
Aug 27, 2012, 10:34:42 AM8/27/12
to toasted-circu...@googlegroups.com
Hi Chris,

Maybe this sketch will help you.  I eliminated all the extraneous functionality and am just setting the LED intensities...

#include <lightuino5.h>

/*? <section name="examples">
<sketch name="lightuino_blink">
This sketch shows basic Lightuino LED control
<verbatim>
*/
 
// Create the basic Lightuino 70 LED sink controller (the pins in the 2 40-pin IDE connectors)
LightuinoSink sinks;  
// Create the Lightuino 16 channel source driver controller (the 16 pin connector)
LightuinoSourceDriver sources;

// This object PWMs the Lightuino sinks allowing individual LED brightness control, and provides array-based access to the Leds
FlickerBrightness pwm(sinks);

// Standard Arduino "setup" function
void setup(void)
  {
  Usb.begin();
 
  Usb.println("Lightuino 5 Blink");
 
    // Start PWMing automatically at around 4000hz.  Generally you'd do this at the beginning of your sketch and leave it on the entire time, not at the beginning of a function.
  pwm.StartAutoLoop(4000);

  // Set every other on
  for (int i=0;i<Lightuino_NUMOUTS;i+=2)
    {
      pwm.brightness[i]=Lightuino_MAX_BRIGHTNESS;
    } 

  }
 
void loop(void)
{  
  for (int i=0;i<Lightuino_NUMOUTS;i++)
    {
      if (pwm.brightness[i]>=Lightuino_MAX_BRIGHTNESS) pwm.brightness[i]=0;
      //else pwm.brightness[i]=Lightuino_MAX_BRIGHTNESS;
      else pwm.brightness[i]+=Lightuino_MAX_BRIGHTNESS/3;
    }
  delay(250);


/*? </verbatim></sketch></section>
*/
Reply all
Reply to author
Forward
0 new messages