Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Revision of Mapping of Potentiometer and LEDs from Wed, 09/19/2007 - 15:19

Project Members: 
Jess Kline

Description

I modified the Analog Input code found on the Arduino website to have one potentiometer control the blinking rates of two LEDs. In addition, the code has one LED shine at a time, making the LEDs resemble the on and off blinking of christmas lights. (I used green and red lights to enhance this effect.)

Components

  • Previous lab setup: green and red LEDs, resistors, breadboard, arduino, yellow and green wires
  • Potentiometer with three soldered wires, red yellow and black wires

Code

/*
 * AnalogInput
 * by DojoDave <http://www.0j0.org>
 *
 * Turns on and off a light emitting diode(LED) connected to digital 
 * pin 13. The amount of time the LED will be on and off depends on
 * the value obtained by analogRead(). In the easiest case we connect
 * a potentiometer to analog pin 2.
 *
 * In Jess' modified version the code turns on and off two LEDs connected
 * to digital pins 9 and 11. The potentiometer is connected to analog pin
 * 0.
 */

int potPin = 0;    // select the input pin for the potentiometer
int ledPin1 = 9;   // select the pin for the first LED
int ledPin2 = 11;   // select the pin for the second LED
int val = 0;       // variable to store the value coming from the sensor

void setup() {
  pinMode(ledPin1, OUTPUT);  // declare the ledPin1 as an OUTPUT
  pinMode(ledPin2, OUTPUT);  // declare the ledPin2 as an OUTPUT
}

void loop() {
  val = analogRead(potPin);    // read the value from the sensor
  digitalWrite(ledPin1, HIGH);  // turn the ledPin1 on
  digitalWrite(ledPin2, LOW);  // turn the ledPin2 on
  delay(val);                  // stop the program for some time
  digitalWrite(ledPin1, LOW);   // turn the ledPin off
  digitalWrite(ledPin2, HIGH);   // turn the ledPin off
  delay(val);                  // stop the program for some time
}

Pictures


Powered by Drupal - Design by Artinet