learning the ropes

things I made at ITP and after: sketches, prototypes, and other documentation

Monday, September 25, 2006

Lab 2 – Analog Inputs (part 1)

LAB 3 - Pulse Width Modulation

In addition to the adjustable LED level suggested in the lab notes, I decided to program the Arduino board to gradually fade the LED level down from the level set by the potentiometer. Last week when I was working on my game of catch I wanted to have the first LED gently fade in and out during the “wind-up” phase of the throw. This week, I figured out how to do it.

/* PWM Lab
I've added my own twist to the code to make the the LED fade

Michael Chladil
*/

#define ANALOG_INPUT  0
#define PWM_OUTPUT    9
#define DELAY_TIME    10

int  potValue        = 0;
long lastMillis      = 0;
int  currentLEDLevel = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
potValue = analogRead (ANALOG_INPUT);

Serial.println (potValue);
/* Use the value read from the potentiometer to determine
a starting level for the LED.                          */

for (currentLEDLevel = potValue; currentLEDLevel >= 0; currentLEDLevel--)
{
analogWrite(PWM_OUTPUT, currentLEDLevel);
delay (DELAY_TIME);
}

delay (DELAY_TIME);
}
posted by Michael at 10:56 pm  

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress