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<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 <= 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 >= 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

Leave a Reply