Lab03

Description

I used Arduino with three LEDs (red, blue and green) and 3 potentiometers. I edited the sketch code to control the red LED’s blinking speed and the brightness of green and blue LED with three different potentiometers .  The result, as shown in the image below, is quite as expected. The blinking speed of the red LED and the brightness of the green and blue LED is controlled by the plot sucessfully.

Components

  • 1 Arduino
  • 3 LED
  • 3 Resistor (220Ω)
  • 1 Breadboard
  • 3 Pots

Code

/*
 Analog Input
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning 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().

The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground

* Note: because most Arduinos have a built-in LED attached
 to pin 13 on the board, the LED is optional.

Created by David Cuartielles
 modified 20 Sep. 2016
 By Owen Hsiao

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/AnalogInput

*/

int sensorPin = A0; // select the input pin for the potentiometer
 //int bsensorPin = A1; // select the input pin for the potentiometer
 //int ledPin = 13; // select the pin for the LED
 int ledPin = 9;
 //int bledPin = 10;
 //int greenledPin = 11;
 int sensorValue = 0; // variable to store the value coming from the sensor
 //int bsensorValue = 0; // variable to store the value coming from the sensor

int potPin = A1; // Analog input pin that the potentiometer is attached to
 int potValue = 0; // value read from the pot

int potPin2 = A2; // Analog input pin that the potentiometer is attached to
 int pot2Value = 0; // value read from the pot
 int led = 10; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 10
 int led2 = 11; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 11

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin, OUTPUT);
 // declare the bledPin as an OUTPUT:
 // pinMode(bledPin, OUTPUT);

// initialize serial communications at 9600 bps:
 Serial.begin(9600);
 // declare the led pin as an output:
 pinMode(led, OUTPUT);

// initialize serial communications at 9600 bps:
 Serial.begin(9600);
 // declare the led pin as an output:
 pinMode(led2, OUTPUT);
 }

void loop() {
 // read the value from the sensor:
 sensorValue = analogRead(sensorPin);
 // turn the ledPin on
 digitalWrite(ledPin, HIGH);
 // stop the program for <sensorValue> milliseconds:
 delay(sensorValue);
 // turn the ledPin off:
 digitalWrite(ledPin, LOW);
 // stop the program for for <sensorValue> milliseconds:
 delay(sensorValue);

potValue = analogRead(potPin); // read the pot value
 analogWrite(led, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
 Serial.println("hello"); // print the pot value back to the debugger pane
 delay(10); // wait 10 milliseconds before the next loop

pot2Value = analogRead(potPin2); // read the pot value
 analogWrite(led2, pot2Value/5); // PWM the LED with the pot value (divided by 4 to fit in a byte)
 Serial.println("hello"); // print the pot value back to the debugger pane
 delay(10); // wait 10 milliseconds before the next loop
 }
IMAG1134_BURST002 IMAG1135_BURST001

3 pots for 3 LEDs

Components

  • 1 Arduino
  • 1 breadboard
  • 3 LEDs (red, green, blue)
  • 3 potentiometers
  • 3 225-ohm resisters
  • wires

For this lab/hw, I controlled the brightness of each LED with a different potentiometer.

Code
// initialize pot pins
int potPin1 = A0;
int potPin2 = A2;
int potPin3 = A3;

// set pot values;
int potV1 = 0;
int potV2 = 0;
int potV3 = 0;

// initialize leds
int blueLed = 6;
int redLed = 9;
int greenLed = 11;

void setup() {
Serial.begin(9600);
// declare the led pin as an output:
pinMode(blueLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}

void loop() {
potV1 = analogRead(potPin1);
potV2 = analogRead(potPin1);
potV3 = analogRead(potPin1); // read the pot value
analogWrite(blueLed, potV1/4);
analogWrite(redLed, potV2/4);
analogWrite(greenLed, potV3/4);

delay(10); // wait a bit, for serial data
}

 

IMG_7616

Lab 3: 3 Potentiometers for 3 LEDs

In this lab the brightness of 3 LED lights are each capable of being independently controlled by its own coinciding potentiometer.

 

components

  • 1 Arduino
  • 1 breadboard
  • 1 red LED
  • 1 green LED
  • 1 blue LED
  • 3 potentiometers
  • 3 225-ohm resisters
  • wires

 

code

int potPinB = 0; // Analog input pin that the potentiometer is attached to
int potValueB = 0; // value read from the pot
int ledB = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
int potPinG = 1; // Analog input pin that the potentiometer is attached to
int potValueG = 0; // value read from the pot
int ledG = 10; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 10
int potPinR = 2; // Analog input pin that the potentiometer is attached to
int potValueR = 0; // value read from the pot
int ledR = 11; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 11
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// declare the led pin as an output:
pinMode(ledB, OUTPUT);
pinMode(ledG, OUTPUT);
pinMode(ledR, OUTPUT);
}

void loop() {
potValueB = analogRead(potPinB); // read the pot value
potValueG = analogRead(potPinG); // read the pot value
potValueR = analogRead(potPinR); // read the pot value
analogWrite(ledB, potValueB/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
analogWrite(ledG, potValueG/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
analogWrite(ledR, potValueR/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
}

 

 

 

IMG_7613

Controlling LEDs with potentiometers

For this assignment, I used an Arduino Uno to control the brightness of three different colored LEDs using three separate potentiometers.

Components:

  • Arduino board
  • Breadboard
  • 3 potentiometers
  • 3 different colored LEDs (red, green, blue)
  • 3 ohm resistors
  • 12 wires

Extra:

I used one potentiometer to control the turning on and off of the three LEDs in sequential order.

/* POT to LED test -> by Owen Mundy March 11, 2010
 from: http://itp.nyu.edu/physcomp/Labs/AnalogIn
—————————————————————*/

// Analog input pin that the potentiometer is attached to 
int potPinBlue = A0; 
int potPinRed = A1;
int potPinGreen = A2;
// value read from the pot
int potValueBlue = 0;
int potValueRed = 0;
int potValueGreen = 0; 
// setting pins to the LEDs
int Blueled = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
int Redled = 10; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 10
int Greenled = 11; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 11
 
void setup() {
 // initialize serial communications at 9600 bps:
 Serial.begin(9600);
 // declare the led pin as an output:
 pinMode(Blueled, OUTPUT);
 pinMode(Redled, OUTPUT);
 pinMode(Greenled, OUTPUT);
}
 
void loop() {
 potValueBlue = analogRead(potPinRed);
 potValueRed = analogRead(potPinGreen);
 potValueGreen = analogRead(potPinBlue); // read the pot value
 // turning pins on
 analogWrite(Blueled, potValueBlue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
 analogWrite(Redled, potValueRed/4);
 analogWrite(Greenled, potValueGreen/4); 
 delay(10); // wait 10 milliseconds before the next loop
}
Extra:
byte ledPin[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; //pins used for LED's
int potPin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

void setup()
{
 for(int i = 0; i < 13; i++){ 
 pinMode(ledPin[i],OUTPUT);
 } 
 
}

void loop()
{
val = analogRead(potPin); // reads the value of the potentiometer (value between 0 and 1023)
 for (int i = 0; i < 13; i++) {
 if((i * 102) > val) { digitalWrite(ledPin[i], HIGH);}
 else
 { digitalWrite(ledPin[i], LOW);}
 }
}
IMG_7396 IMG_7397

Video of me controlling LED brightness

Extra video: Sequential LEDs

Variable rate LED

Description


This circuit uses two potentiometers, one to control the brightness of the LED and the other to control the blinking rate. Within each blink, the brightness is held constant. All measurements are done using analog inputs on the Arduino.

Components


  • Arduino
  • 1 LED
  • 1 Resistor (220Ω)
  • 7 Wires
  • 1 Breadboard
  • 2 Potentiometers

Code



int rateSensorPin = A0;    // select the input pin for the rate potentiometer
int brightSensorPin = A2;  // select the input pin for the brightness potentiometer
int ledPin = 9;      // select the pin for the LED
int rateValue = 0;  // variable to store rate pot value
int brightValue = 0;  // variable to store brightness pot value
void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the sensors:
  rateValue = analogRead(rateSensorPin);
  brightValue = analogRead(brightSensorPin);
  
  // turn the ledPin on, convert from 0-1023 scale to 0-255
  analogWrite(ledPin, brightValue/4);
  // stop the program for <rateVale> milliseconds:
  delay(rateValue);
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for for <rateValue> milliseconds:
  delay(rateValue);
}
Potentiometer circuit

Lab 3 – 3 Potentiometers to Control 3 LEDs

Description

I used an Arduino-Uno as a microprocessor to control the brightness of three LED lights, realized through three different rates, which are translated from data fed in from three different potentiometers.

Components

  • 1 Arduino Uno
  • 1 Breadboard
  • 3 LEDs (red, green, and blue)
  • 3 Resistor (220Ω)
  • 3 Potentiometers
  • 1 USB Cable
  • 21 Jumper Wires
  • 1 Laptop

Code

int sensorPin1 = A0; // select the input pin for the potentiometer
int sensorPin2 = A1; // select the input pin for the potentiometer
int sensorPin3 = A2; // select the input pin for the potentiometer
int ledPin1 = 9; // select the pin for the LED
int ledPin2 = 10; // select the pin for the LED
int ledPin3 = 11; // select the pin for the LED

int sensorValue1 = 0; // variable to store the value coming from the sensor
int sensorValue2 = 0; // variable to store the value coming from the sensor
int sensorValue3 = 0; // variable to store the value coming from the sensor

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin1, OUTPUT);
 pinMode(ledPin2, OUTPUT);
 pinMode(ledPin3, OUTPUT);
 Serial.begin(5600);

}

void loop() {
 // read the value from the sensor:
 sensorValue1 = analogRead(sensorPin1);
 sensorValue2 = analogRead(sensorPin2);
 sensorValue3 = analogRead(sensorPin3);

 // turn the ledPin on
 analogWrite(ledPin1, sensorValue1/5);
 analogWrite(ledPin2, sensorValue2/5);
 analogWrite(ledPin3, sensorValue3/5);
}
Photo

IMG_0677

Lab 3: LED Pulses

Description

This program fades three LEDs to a brightness determined by one potentiometer with a pause between fades determined by another potentiometer. The overall effect is intended to mimic pules/heartbeats, where the brightness could be analogous to beat strength and the pause time analogous to beat rate.

I interpreted the “mapping between the rotational position pot and LED output” to mean a map between the potentiometers’ visual configurations and the output (perhaps a misinterpretation – I’ll find out!), so I made two gauges to fit over the pots. On one gauge, the size of the heart corresponds to beat strength (the max brightness in the pulse) while on the other gauge, the rate diagrams of variable spaces are intended to convey the idea of slower or faster pulses.

Components

  • Arduino UNO board
  • 1 red, 1 green, and 1 blue LED
  • connector wires
  • 2 potentiometers
  • paper
  • markers
  • tape

Code

/*
LEDs are faded up to a brightness determined by one sensor at a rate (frequency)
determined by the other.
*/
int speedSensor = A0; //input pin for the speed potentiometer (how fast)
int brightSensor = A2; //input pin for the brightness potentiometer (how bright)
// select the pins for LED output:
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
int speedValue = 0; //variable to store the value coming from the speed sensor
int brightValue = 0; //variable to store the value coming from the brightness sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop() {
speedValue = analogRead(speedSensor); // read the value from the speed sensor
brightValue = analogRead(brightSensor); // read the value from the brightness sensor

//if the brightness is too low, there will be no steps calculated:
if(brightValue&lt;80)
brightValue = 80;

/* fade in from min to max. To keep the same number of increments,
increment fadeValue by brightValue/80 */
for (int fadeValue = 0 ; fadeValue &lt;= brightValue/4; fadeValue += brightValue/80) { 
// sets the value (range from 0 to brightValue/4): 
analogWrite(redPin, fadeValue); 
analogWrite(greenPin, fadeValue); 
analogWrite(bluePin, fadeValue); 
// wait to see the dimming effect:
 delay(10); 
} 
/* fade out from max to min. To keep the same number of increments,
increment fadeValue by brightValue/80 */ 
for (int fadeValue = brightValue/4 ; fadeValue &gt;= 0;  fadeValue -= brightValue/80) {
// sets the value (range from 0 to brightValue/4):
analogWrite(redPin, fadeValue);
analogWrite(greenPin, fadeValue);
analogWrite(bluePin, fadeValue);
// wait to see the dimming effect:
delay(10);
}
//depending on the math, the min may not be 0. set pins to 0 for the long delay:
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);

//wait for a time determined by the speed analog input:
delay(speedValue/1.5);
}
setup scale detail

Lab/HW 3 – Potentiometer to control LEDs

Description
For the Lab, I used two potentiometers to control the brightness and blinking rate of the three LEDs.

Extra Point
For this portion of the Lab, I used the rotation of one potentiometer to control the brightness of the three LED’s. The other potentiometer controls the gaps and duration between the blinking of the individual LEDs.

Lab Material

 

  • Jumper cables
  • Potentiometers (2)
  • Ping pong ball diffuser
  • Cotton
  • Arduino
  • 3 LED’s
  • Breadboard

 

HW/LAB

int sensorPin_blink = A0;
int sensorPin_bright = A1;// select the input pin for the potentiometer
int ledPin = 13;
int redledPin = 9;
int blueledPin = 10;
int greenledPin = 11;// select the pin for the LED
int sensorValue_blink = 0;
int sensorValue_bright = 0;// variable to store the value coming from the sensor

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin, OUTPUT);
 pinMode(redledPin, OUTPUT); // sets the pins as output
 pinMode(greenledPin, OUTPUT);
 pinMode(blueledPin, OUTPUT);
}

void loop() {
 // read the value from the sensor:
 sensorValue_blink = analogRead(sensorPin_blink);
 sensorValue_bright = analogRead(sensorPin_bright);
 // turn the ledPin on
 analogWrite(redledPin, sensorValue_bright/4);
 analogWrite(greenledPin, sensorValue_bright/4);
 analogWrite(blueledPin, sensorValue_bright/4);
 // stop the program for &lt;sensorValue&gt; milliseconds:
 delay(sensorValue_blink);
 // turn the ledPin off:
 analogWrite(redledPin, 0);
 analogWrite(greenledPin, 0);
 analogWrite(blueledPin, 0);
 // stop the program for for &lt;sensorValue&gt; milliseconds:
 delay(sensorValue_blink);
}
 

Extra Point

int sensorPin_blink = A0;
int sensorPin_bright = A1;// select the input pin for the potentiometer
int ledPin = 13;
int redledPin = 9;
int blueledPin = 10;
int greenledPin = 11;// select the pin for the LED
int sensorValue_blink = 0;
int sensorValue_bright = 0;// variable to store the value coming from the sensor

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin, OUTPUT);
 pinMode(redledPin, OUTPUT); // sets the pins as output
 pinMode(greenledPin, OUTPUT);
 pinMode(blueledPin, OUTPUT);
}

void loop() {
 // read the value from the sensors:
 sensorValue_blink = analogRead(sensorPin_blink);
 sensorValue_bright = analogRead(sensorPin_bright);
 // turn the ledPin on
 analogWrite(redledPin, sensorValue_bright/4);
 delay(sensorValue_blink);
 analogWrite(blueledPin, sensorValue_bright/4);
 // stop the program for &lt;sensorValue&gt; milliseconds:
 delay(sensorValue_blink);
 analogWrite(greenledPin, sensorValue_bright/4);
 delay(sensorValue_blink);
 // turn the ledPin off:
 analogWrite(redledPin, 0);
 analogWrite(greenledPin, 0);
 analogWrite(blueledPin, 0);
 // stop the program for for &lt;sensorValue&gt; milliseconds:
 delay(sensorValue_blink);
}

<img class="alignnone size-medium wp-image-859" src="http://blogs.ischool.berkeley.edu/i262/files/2016/09/IMG_7345-300x225.jpg" alt="IMG_7345" width="300" height="225" />
<a href="http://blogs.ischool.berkeley.edu/i262/files/2016/09/IMG_7341.mov">Video</a>
 

Lab03 Rotating piano and forte

Description

For the normal lab requirement, I had one rotating control for brightness and one rotating control for blinking rate. I mapped these controls using soldered potentiometers.

For extra credit, I  wanted to improve upon my previous piano/forte Lab 2. I mapped one pot to a variable called dynamic, which when rotated would switch from ‘p’ mode to ‘mp mode’ to ‘f’ mode. The other pot mapped to the blinking rate.

Materials

  • Jumper cables
  • Potentiometers (2)
  • Ping pong ball diffuser
  • Cotton
  • Arduino
  • 3 LED’s
  • Breadboard
  • Code (Lab Requirement)

    
    int sensorPin = A0;
    int sensorPin2 = A1; // select the input pin for the potentiometer
    int ledPin = 11;      // select the pin for the LED
    int ledPin2 = 10;
    int ledPin3 = 9;
    int sensorValue = 0;  // variable to store the value coming from the sensor
    int sensorValue2 = 0;
    
    void setup() {
      // declare the ledPin as an OUTPUT:
      pinMode(sensorPin, INPUT);
      pinMode(sensorPin2, INPUT);
      pinMode(ledPin, OUTPUT);
      pinMode(ledPin2, OUTPUT);
      pinMode(ledPin3, OUTPUT);
      Serial.begin(9600);
    }
    
    void loop() {
      // read the value from the sensor:
    
      sensorValue = analogRead(sensorPin);
      sensorValue2 = analogRead(sensorPin2);
      Serial.print(sensorValue);
      Serial.print(",");
      Serial.print(sensorValue2);
      Serial.println("");
      // turn the ledPin on
      analogWrite(ledPin, (sensorValue2 / 4));
      analogWrite(ledPin2, (sensorValue2 / 4));
      analogWrite(ledPin3, (sensorValue2 / 4));
      // stop the program for  milliseconds:
      delay(sensorValue);
      analogWrite(ledPin, 0);
      analogWrite(ledPin2, 0);
      analogWrite(ledPin3, 0);
      // stop the program for  milliseconds:
      delay(sensorValue);
    }
    

    Code (Extra Credit)

    
    // Output
    int sensorPin = A0;
    int sensorPin2 = A1; // select the input pin for the potentiometer
    int greenPin   = 9;   // Red LED,   connected to digital pin 9
    int bluePin = 10;  // Green LED, connected to digital pin 10
    int redPin  = 11;  // Blue LED,  connected to digital pin 11
    int dynamic = 0;
    // Program variables
    int blueVal   = 0; // Variables to store the values to send to the pins
    int greenVal = 0 ;   // Initial values are Red full, Green and Blue off
    int redVal  = 0;
    int repeat = 0;
    int i = 0;     // Loop counter    
    int wait = 25; // 50ms (.05 second) delay; shorten for faster fades
    //int DEBUG = 0; // DEBUG counter; if set to 1, will write values back via serial
    
    void setup()
    {
      pinMode(sensorPin, INPUT);
      pinMode(sensorPin2, INPUT);
      pinMode(redPin,   OUTPUT);   // sets the pins as output
      pinMode(greenPin, OUTPUT);   
      pinMode(bluePin,  OUTPUT); 
      Serial.begin(9600);
      Serial.println("rotate right or left to go more p or more f");  
    }
    
    // Main program
    void loop()
    {
      dynamic = analogRead(sensorPin);
      wait = analogRead(sensorPin2);
      if (dynamic &lt; 300) {
        redVal = 0;
        greenVal = 0;
        blueVal = 0;
         
            i = 0;
            for (; i &lt;50; i++) {
                Serial.print(&quot;dynamic &quot;);
                Serial.print(dynamic);
                Serial.print(&quot; wait &quot;);
                Serial.print(wait/8);
                Serial.println();
                blueVal += 1 ;
                Serial.println(dynamic);
                analogWrite(redPin, redVal);
                analogWrite(greenPin, greenVal);
                analogWrite(bluePin, blueVal);
                delay(wait/8);
            }
            for (; i &lt;100;i++) {
              blueVal -= 1;
              analogWrite(redPin, redVal);
              analogWrite(greenPin, greenVal);
              analogWrite(bluePin, blueVal);
              delay(wait/8);
            }
         
      }
      else if (dynamic &lt; 700) {
        redVal = 0;
        greenVal = 0;
        blueVal = 0;
        i = 0;
            for (; i &lt;50; i++) {
                redVal += 2;
                greenVal += 1;
                blueVal = 1;
                Serial.print(&quot;dynamic &quot;);
                Serial.print(dynamic);
                Serial.print(&quot; wait &quot;);
                Serial.print(wait/8);
                Serial.println();
                analogWrite(redPin, redVal);
                analogWrite(greenPin, greenVal);
                analogWrite(bluePin, blueVal);
                delay(wait/8);
            }
            for (; i &lt;100;i++) {
              greenVal -= 1;
              redVal -= 2;
              analogWrite(redPin, redVal);
              analogWrite(greenPin, greenVal);
              analogWrite(bluePin, blueVal);
              delay(wait/8);
            }
          
          redVal = 0;
      }
      else if (dynamic &lt; 1050) {
        redVal = 255;
        greenVal = 0;
        blueVal = 0;
        i = 0;
          for (; i &lt;50; i++) {
                Serial.print(&quot;dynamic &quot;);
                Serial.print(dynamic);
                Serial.print(&quot; wait &quot;);
                Serial.print(wait/8);
                Serial.println();
              redVal -= 3;
              greenVal = greenVal;
              blueVal += 1;
              Serial.println(dynamic);
              analogWrite(redPin, redVal);
              analogWrite(greenPin, greenVal);
              analogWrite(bluePin, blueVal);
              delay(wait/8);
          }
          for (; i &lt;100;i++) {
            redVal = redVal;
            greenVal += 2;
            blueVal = blueVal;
            analogWrite(redPin, redVal);
            analogWrite(greenPin, greenVal);
            analogWrite(bluePin, blueVal);
            delay(wait/8);
          }
          for (; i &lt;150;i++) {
            redVal += 3;
            greenVal -= 1;
            blueVal  -= 1;
            analogWrite(redPin, redVal);
            analogWrite(greenPin, greenVal);
            analogWrite(bluePin, blueVal);
            delay(wait/8);
          }
          redVal = 0;
          greenVal = 0;
          blueVal = 0;
          analogWrite(redPin, redVal);
          analogWrite(greenPin, greenVal);
          analogWrite(bluePin, blueVal);  
        }
      else { 
      }
    }
    
    

    This is what happens when dynamic is set to the highest and wait is set to almost the lowest. The color crescendo is really fast.

     

    Control the brightness of 3 LED lights

    Description

    I used 3 potentiometers to light three LED lights. Each potentiometer controls the brightness of one LED light.

    Components

    • 1 Arduino
    • 3 LEDs
    • 3 Resistors (220Ω)
    • 3 Potentiometers
    • 1 Breadboard

    Code

    // select the input pin for the potentiometer
    int sensorPinRed = A0;    
    int sensorPinGreen = A1;    
    int sensorPinBlue = A2;
    // select the pin for the LEDs
    int redPin = 9;      
    int greenPin = 10;
    int bluePin = 11;
    // variable to store the value coming from the sensor
    int sensorValueRed = 0;
    int sensorValueGreen = 0;
    int sensorValueBlue = 0;
    
    void setup() {
      // declare the ledPin as an OUTPUT:
      pinMode(redPin, OUTPUT);
      pinMode(greenPin, OUTPUT);
      pinMode(bluePin, OUTPUT);
      Serial.begin(9600);
    }
    
    void loop() {
      // read the value from the sensor:
      sensorValueRed = analogRead(sensorPinRed);
      sensorValueGreen = analogRead(sensorPinGreen);
      sensorValueBlue = analogRead(sensorPinBlue);
      
      // turn the Pins on
      analogWrite(redPin, sensorValueRed/4);
      analogWrite(greenPin, sensorValueGreen/4);
      analogWrite(bluePin, sensorValueBlue/4);
    
      // stop the program for 10 milliseconds:
      delay(10);
    }
    
    
    pot_brightness