Lab 3

victorpras's picture

Lab 3 by Victor Tjhia

Description

use 1 potentiometer to determine blinking rate of 3 LEDs, and another to dim.

Components Used

·         3 Light Emitting Diode (LED) RGB

·         Resistor

·         Arduino

·         Solderless Board

·        Potentiometer

 

/*
 * one pot dims, the other pot changes the blinking rate of 3 LEDs
 * 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 pot1Val = 0;   // variable to store the value coming from pot 1
int pot2Val = 0;   // variable to store the value coming from pot 2
int led1Pin = 9;   // select the pin for the LED 1
int led2Pin = 10; // select the pin for the LED 2
int led3Pin = 11;
void setup() {
   pinMode(led1Pin, OUTPUT);  // declare the led1Pin as an OUTPUT
   pinMode(led2Pin, OUTPUT);  // declare the led2Pin as an OUTPUT
}
void loop() {
   pot1Val = analogRead(pot1Pin);   // read the value from pot 1, between 0 - 1024, for dimming
   pot2Val = analogRead(pot2Pin);   // read the value from pot 2, between 0 - 1024, for blinking
   analogWrite(led1Pin, pot1Val); // dim LED to value from pot1
   analogWrite(led2Pin, pot1Val);
   analogWrite(led3Pin, pot1Val);
   delay(pot2Val);                  // stop the program for some time, meaning, LED is on for this time
   analogWrite(led1Pin, 0);         // dim LED to completely dark (zero)
   analogWrite(led2Pin, 0);
   analogWrite(led3Pin, 0);
   delay(pot2Val);                  // stop the program for some time, meaning, LED is OFF for this time
}

1blink1fade.jpg
0
Your rating: None