Pages: [1]   Go Down
Author Topic: UNO + PWM Shield + 32 LEDs + ZERO Experience  (Read 1441 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Let me give you a brief preface...

So I have done a little programming/building in the past (not related to Arduino) and tend to be a generally/mildly algorithmic/electronics savvy person.  So an artist friend of mine naturally calls me the day before his show opening wanting me to make the Arduino unit he just purchase work.  I now have about 15 minutes of experience in the Arduino world, which basically equates to me browsing this forum about trying to do a crash-coarse on related code.  I have absolutely no idea what I am doing, so I am reaching out for your help.

The friend purchased and UNO, a PMW Shield with 32 PMW outputs, and 32 LEDS.  He sent me some images of his work, and though i don't have experience specifically with Aruino boards, it looks to me like he managed to connect everything properly.  So now he needs code to get it all up and running.

He has an art piece with 32 LEDs randomly placed inside the piece.  All the wires are run and he seems to have a grasp with polarity.  What he is trying to do is have the LED fade in and out at random (LED chaos). 

As I said, I have no idea what I am doing.  I found some code posted on the forum that sounded familiar to this application and took a guess at how to alter it for him.  This could be totally off the mark.  Can anyone tell me if I am on the right track?  If you have code I can use, ever better

Any help is greatly appreciated!!!

Here is what I came up with:         

Code:

#define LED1 1
#define LED2 2
#define LED3 3
#define LED4 4
#define LED5 5
#define LED6 6
#define LED7 7
#define LED8 8
#define LED9 9
#define LED10 10
#define LED11 11
#define LED12 12
#define LED13 13
#define LED14 14
#define LED15 15
#define LED16 16
#define LED17 17
#define LED18 18
#define LED19 19
#define LED20 20
#define LED21 21
#define LED22 22
#define LED23 23
#define LED24 24
#define LED25 25
#define LED26 26
#define LED27 27
#define LED28 28
#define LED29 29
#define LED30 30
#define LED31 31
#define LED32 32



void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
pinMode(LED8, OUTPUT);
pinMode(LED9, OUTPUT);
pinMode(LED10, OUTPUT);
pinMode(LED11, OUTPUT);
pinMode(LED12, OUTPUT);
pinMode(LED13, OUTPUT);
pinMode(LED14, OUTPUT);
pinMode(LED15, OUTPUT);
pinMode(LED16, OUTPUT);
pinMode(LED17, OUTPUT);
pinMode(LED18, OUTPUT);
pinMode(LED19, OUTPUT);
pinMode(LED20, OUTPUT);
pinMode(LED21, OUTPUT);
pinMode(LED22, OUTPUT);
pinMode(LED23, OUTPUT);
pinMode(LED24, OUTPUT);
pinMode(LED25, OUTPUT);
pinMode(LED26, OUTPUT);
pinMode(LED27, OUTPUT);
pinMode(LED28, OUTPUT);
pinMode(LED29, OUTPUT);
pinMode(LED30, OUTPUT);
pinMode(LED31, OUTPUT);
pinMode(LED32, OUTPUT);
 }

void loop()
{
  int fadeUpDelay = random(10, 60);
  int fadeDownDelay = random(10, 60);
 
  for(int c=0; c < 255; c++)
  {
    analogWrite(LED1, c);
analogWrite(LED1, c);
analogWrite(LED2, c);
analogWrite(LED3, c);
analogWrite(LED4, c);
analogWrite(LED5, c);
analogWrite(LED6, c);
analogWrite(LED7, c);
analogWrite(LED8, c);
analogWrite(LED9, c);
analogWrite(LED10, c);
analogWrite(LED11, c);
analogWrite(LED12, c);
analogWrite(LED13, c);
analogWrite(LED14, c);
analogWrite(LED15, c);
analogWrite(LED16, c);
analogWrite(LED17, c);
analogWrite(LED18, c);
analogWrite(LED19, c);
analogWrite(LED21, c);
analogWrite(LED22, c);
analogWrite(LED23, c);
analogWrite(LED24, c);
analogWrite(LED25, c);
analogWrite(LED26, c);
analogWrite(LED27, c);
analogWrite(LED28, c);
analogWrite(LED29, c);
analogWrite(LED30, c);
analogWrite(LED31, c);
analogWrite(LED32, c);
    delay(fadeUpDelay);
  }
 
  for(int c=255; c > 0; c--)
  {
    analogWrite(LED1, c);
analogWrite(LED2, c);
analogWrite(LED3, c);
analogWrite(LED4, c);
analogWrite(LED5, c);
analogWrite(LED6, c);
analogWrite(LED7, c);
analogWrite(LED8, c);
analogWrite(LED9, c);
analogWrite(LED10, c);
analogWrite(LED11, c);
analogWrite(LED12, c);
analogWrite(LED13, c);
analogWrite(LED14, c);
analogWrite(LED15, c);
analogWrite(LED16, c);
analogWrite(LED17, c);
analogWrite(LED18, c);
analogWrite(LED19, c);
analogWrite(LED21, c);
analogWrite(LED22, c);
analogWrite(LED23, c);
analogWrite(LED24, c);
analogWrite(LED25, c);
analogWrite(LED26, c);
analogWrite(LED27, c);
analogWrite(LED28, c);
analogWrite(LED29, c);
analogWrite(LED30, c);
analogWrite(LED31, c);
analogWrite(LED32, c);
    delay(fadeDownDelay);
  }
 
  delay(10);
 
}

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8945
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The basic Arduino UNO only has 6 PWM output pins so without additional hardware you can only control the brightness of 6 LEDs.  To get 32 LEDS you have a couple of choices:  a PWM shield (http://practicalmaker.com/products/arduino-shields/pwm-shield-assembled) or connecting the LEDs in a matrix and using something like the ShiftPWM library (http://www.elcojacobs.com/shiftpwm/) to do software PWM on the matrix.

Either way you can control the brightness of the 32 LEDs individually and can have them fade in and out at random.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

Thanks, John.  He does have the PWM Shield you listed:  http://practicalmaker.com/products/arduino-shields/pwm-shield-assembled)

It is just a matter of writing the right code to make it work.

That is the part he could use some help on.   
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 633
Posts: 34514
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You will normally find example code with the shield.
If not look at what chip it contains and see if there is a libary for that chip. If all else fails get the data sheet and waggle the lines like it tells you to.

Edit, look at this
http://www.arduino.cc/playground/Learning/TLC5940
It is for this chip.
« Last Edit: October 05, 2012, 05:32:12 pm by Grumpy_Mike » Logged

Pages: [1]   Go Up
Jump to: