Pulse Width Modulation of 4 LEDs

PWM of four LEDs at various intervals using Arduino.  Recorded with two photocells and Zoom H2.

Spectrogram of recording:

Spectrogram edited to enhance patterns:


// Fade x 4
// Fading four LEDs in and out at various intervals.

 int brightness = 0; // how bright the LED is
 int fadeAmount = 50; // how many points to fade the LED by

void setup() {
 // declare pin 9 to be an output:
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);

void loop() {
 // set the brightness of pin 9:
 analogWrite(10, brightness);
 analogWrite(11, brightness*2);
 analogWrite(5, brightness*3);
 analogWrite(6, brightness*4);
 // change the brightness for next time through the loop:
 brightness = brightness + fadeAmount;
 // reverse the direction of the fading at the ends of the fade:
 if (brightness == 0 || brightness == 255) {
 fadeAmount = -fadeAmount ;
 // wait for 30 milliseconds to see the dimming effect

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: