Lab 3: Pot Control

Submitted by elee on Wed, 02/20/2013 - 02:54
elee's picture

Description

Using the potentiometer on the analog port of the Arduino Uno to control LEDs in interesting ways, in combination with the previous ambiance lighting pattern.

Materials

  • 1-3 Potentiometers
  • 3 Resistors (220 Ohms)
  • 1 Arduino
  • 3 LEDs (Red, Green, Blue)
  • Many Wires

Code

 

// Output
int redPin   = 10;   // Red LED,   connected to digital pin 9
int greenPin = 11;  // Green LED, connected to digital pin 10
int bluePin  = 9;  // Blue LED,  connected to digital pin 11
int sensorPin = A0;
int sensorValue = 0;
 
int sensorPin2 = A5;
int sensorValue2 = 0;
 
// Program variables
int redVal   = 255; // Variables to store the values to send to the pins
int greenVal = 1;   // Initial values are Red full, Green and Blue off
int blueVal  = 1;
 
int i = 0;     // Loop counter    
int wait = 10; // 50ms (.05 second) delay; shorten for faster fades
int DEBUG = 0; // DEBUG counter; if set to 1, will write values back via serial
 
int myMax = 30; // observed 'maximum' value
 
void setup()
{
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT); 
  if (DEBUG) {           // If we want to see the pin values for debugging...
    Serial.begin(9600);  // ...set up the serial ouput on 0004 style
  }
  Serial.begin(9600);
}
 
// Main program
void loop()
{
  int valBright = analogRead(sensorPin2);
 
  int valBlink = analogRead(sensorPin);
 
  analogWrite(redPin, valBright/4);
  analogWrite(greenPin, valBright/4);
  analogWrite(bluePin, valBright/4);
  
  delay(valBlink/4);
  
  digitalWrite(redPin, LOW);
  digitalWrite(greenPin, LOW);
  digitalWrite(bluePin, LOW);
  delay(valBlink/4);   
}
Since upload wasn't working (Pictures):

 

0
Your rating: None
Drupal theme by Kiwi Themes.