(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



Watch the blinking lights


2007/11/12



This simple project demonstrates the analog output capability of the Wiring.org I/O board.

All you need for this is the Wiring I/O board, some hookup wires, a breadboard, and two LEDS. A voltmeter makes it easier to check your wiring if you aren't sure of yourself, but isn't necessary.

I took the program from Wirings Sketchbook examples and modified it for this project.


// LED Fade 
// by BARRAGAN <http://barraganstudio.com>
// Modified by Tony Lawrence for two leds

// Demonstrates the use of PWM pins (analog output) by dimming 
// a light (LED) from off to maximum intensity and back.

// Created 5 February 2004
// Revised 7 May 2007

int value = 0;  // variable to keep the actual value 
int ledpin = 0; // light connected to analog pin 0
int ledpin2=5; // light connected to analog pin 5
int value2=0;  // hold values for pin 5

void setup()
{
  // nothing for setup 
}

void loop()
{
  value2=255;
  for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
  {
    analogWrite(ledpin, value);           // sets the value (range from 0 to 255)
    analogWrite(ledpin2,value2);
    value2-=5;
    delay(30);     // waits for 30 milli seconds to see the dimming effect
  }
  value2=0;
  for(value = 255; value >=0; value-=5)   // fade out (from max to min)
  {
    analogWrite(ledpin, value);
    analogWrite(ledpin2,value2);
    value2+=5;
    delay(30);
  } 
  
  
}
 

If you compile this in Wiring and upload it to the board, it will start varying voltage to pins 0 and 5 of the analog outputs. These are the PWM (Pulse Width Modulation) pins in the upper right hand corner of the board. You can measure this with a volt meter (set to the 15V DC scale). Attach the negative lead of your meter to ground (two ground pins are available at the bottom right of the Wiring.org board) and touch the positive to pin 0 or pin 5 of the PWM pins. You'll see the voltage swinging from 0 to 5 volts.

Those pins actually work in the same way most dimmers do. They actually switch on and off thousands of times per second - this Wikipedia article gives the general idea.

In the book Making Things Talk, the PWM outputs are used to drive a meter based on reading air quality from an Internet web page.

Now let's hook up the LEDS. I used a standard breadboard, but you can use hookup wire and alligator clips too. Basically you want the short leg of each LED hooked up to the ground, and one of the LEDS hooked on its other leg to PWM pin 0, and the other LED connected to PWM pin 5. Simple enough?

I didn't have any hookup wire, so I broke up a couple of RS-232 RJ45 jacks and pulled out the wires.. hey, copper is copper and the male pins are the right size for a breadboard and the females fit reasonably well on the Wiring.org I/O board's pins.

If you hook up your voltmeter while the LEDS are connected, you'll probably see that it won't swing as high if you are powering the board through your computer's USB port. You can't drive a tremendous amount of outputs through USB - you need to hook up a real power supply.

The LED's aren't really dimming; they are actually turning on and off with a different voltage applied on the "on" cycle, but it happens too fast for your eyes to tell. You can experiment with different values for the delay - if you make it long enough, it won't look like dimming any more because the change is too slow. If you make the delay very short (5ms), the lights just seem to blink.

A voltmeter doesn't react so quickly - once it gets a high voltage, it tends to stay there for a bit and vice versa. However, you can certainly tell the difference between 5ms and 30ms.





(If the movie stalls just click on the progress button and it will keep moving.)




Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - Electronics


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress