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 Controlling LEDs with multiple Pots from Wed, 09/19/2007 - 23:27

Project Members: 
n8agrin

Code

Two blinking lights controlled by one POT

/*
 * 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.
 *
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 *
 * Simple Modification to run TWO, yes TWO blinking LEDs
 * by n8agrin.
 */

int potPin = 2;    // select the input pin for the potentiometer
int bluePin = 11;   // select the pin for the LED
int greenPin = 10;
int val = 0;       // variable to store the value coming from the sensor
void setup() {
  pinMode(bluePin, OUTPUT);  // declare the ledPin as an OUTPUT
  pinMode(greenPin, OUTPUT);
}
void loop() {
  val = analogRead(potPin);    // read the value from the sensor
  digitalWrite(bluePin, LOW);  // turn the ledPin on
  digitalWrite(greenPin, HIGH);  // turn the ledPin on
  delay(val);                  // stop the program for some time
  digitalWrite(bluePin, HIGH);   // turn the ledPin off
  digitalWrite(greenPin, LOW);
  delay(val);                  // stop the program for some time
}

 Two POTs, one controls brightness, the other blinking

/*
 * one pot fades one led
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */
int brightnessPotPin   = 2;   // select the input pin for the potentiometer
int blinkPotPin    = 3;

int greenPin = 9;   // select the pin for the LED
int bluePin  = 10;
int redPin   = 11;

int brightness = 0;      // variable to store the value coming from the sensor
int blink = 0;

void setup() {
  Serial.begin(9600);
}
void loop() {
  brightness = analogRead(brightnessPotPin);    // read the value from the sensor, between 0 - 1024
  blink = analogRead(blinkPotPin);
 
  Serial.println(brightness);
  Serial.println(blink);
 
  analogWrite(greenPin, brightness/4); // analogWrite can be between 0-255
  analogWrite(bluePin, brightness/4);
  analogWrite(redPin, brightness/4);
 
  if (blink > 1) { //added this to elminate some weird blinking artifacts
    delay(blink);
    analogWrite(greenPin, 0);
    analogWrite(bluePin, 0);
    analogWrite(redPin, 0);
    delay(blink);
  }
}

 


Powered by Drupal - Design by Artinet