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!


Sensors: Analog input and LEDs

Project Members: 
Sheng-Ying Pao

I use 3 pods to control 3 LEDs.

One pod controls brightness

another pod controls blink frequency

the other pod selects LED ==> the most important one!!

By controling the pod's value, one of the three LEDs will be turned on. When this LED-selecting pod has the greatest value (1023), the three LED will light up in turn.

When the LED-selecting pod has the greatest value (1023), and when the blink frequency-controlling pod has the smallest value (0), the three LED go crazy!!!

My Video:

http://www.youtube.com/v/hef5Worxx0U

My Code:

=== 

/*Aithne Sheng-Ying Pao's HW3
 * pot1Pin controls brightness, pot2Pin controls the blinking frequency, pot3Pin selects one of the three lights or make them on in turn.
 * modification of the following
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */
int pot1Pin = 0;   // select the input pin for the potentiometer 1
int pot2Pin = 1;   // select the input pin for the potentiometer 2
int pot3Pin = 2;   // select the input pin for the potentiometer 3

int pot1Val = 0;   // variable to store the value coming from pot 1
int pot2Val = 0;   // variable to store the value coming from pot 2
int pot3Val = 0;   // variable to store the value coming from pot 3

int ledPin = 11;   // select the initial output pin to 11

void setup() {
   pinMode(ledPin, OUTPUT);  // declare the led1Pin as an OUTPUT
}
void loop() {
   pot1Val = analogRead(pot1Pin);   // read the value from pot 1, between 0 - 1023, for dimming
   pot2Val = analogRead(pot2Pin);   // read the value from pot 2, between 0 - 1023, for blinking
   pot3Val = analogRead(pot3Pin);   // read the value from pot 2, between 0 - 1023, for selecting output pin
  
   //select one of the three pins(lights) by different pot3Val
   if (pot3Val<324){
     ledPin = 9;
     }
   else if (pot3Val<685){
     ledPin = 10;
     }
   else if (pot3Val <1023){
     ledPin = 11;
     }
   //select all three pins, and make the three LED will light in turn by the following for loop.
   else if (pot3Val == 1023) {
     for (ledPin=9; ledPin < 12; ledPin++ ){
         analogWrite(ledPin, pot1Val/4); // dim LED to value from pot1
         delay(pot2Val);                  // stop the program for some time, meaning, LED is on for this time
         analogWrite(ledPin, 0);         // dim LED to completely dark (zero)
         delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
         if (ledPin==12){
           ledPin=9;
         }
      }
    }
   analogWrite(ledPin, pot1Val/4); // dim LED to value from pot1
   delay(pot2Val);                  // stop the program for some time, meaning, LED is on for this time
   analogWrite(ledPin, 0);         // dim LED to completely dark (zero)
   delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
   }


Comments

Aithne, Great job using the

Aithne,

Great job using the pot as a selector!

dave


Powered by Drupal - Design by Artinet