First assignment:
Code allows to control the intensity of three LEDs using three potentiometers. RGB Values are sent to the serial monitor for debugging.
/*
* three pots control intensity of three LEDs
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
*
* Kilian Moser, TUI 2011
*/
int potPin_blue = A5; // input Pin blue
int ledPin_blue = 11; // LED Pin blue
int potPin_green = A4; // input Pin green
int ledPin_green = 6; // LED Pin green
int potPin_red = A3; // input Pin red
int ledPin_red = 5; // LED Pin red
int val_blue = 0; // variable to store the value coming from the sensor
int val_red = 0; // variable to store the value coming from the sensor
int val_green = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val_blue = analogRead(potPin_blue); // read the value from the sensor, between 0 - 1024
val_green = analogRead(potPin_green); // read the value from the sensor, between 0 - 1024
val_red = analogRead(potPin_red); // read the value from the sensor, between 0 - 1024
Serial.print("Blue: ");
Serial.print(val_blue);
Serial.print(" Green: ");
Serial.print(val_green);
Serial.print(" Red: ");
Serial.println(val_red);
analogWrite(ledPin_blue, val_blue/4); // analogWrite can be between 0-255
analogWrite(ledPin_green, val_green/4); // analogWrite can be between 0-255
analogWrite(ledPin_red, val_red/4); // analogWrite can be between 0-255
}
Pictures:
Second assignment
Two potentiometers are used to control the intensity and blinking frequency of one blue LED. Both intensity and frequency are displayed in the serial monitor. the maximum gap between a LED on/off switch is set to ~ 4s.
/*
* two pots to control one LED
* First pot controls frequency
* Second pot controls intensity
*
* Kilian Moser, TUI 2011
*/
int ledPin_blue = 11; // LED Pin blue
int potPin_intensity = A5; // input Pin to control LED intensity
int potPin_frequency = A4; // input Pin to control LED blinking frequency
int val_intensity; // Var to store LED intensity
int val_frequency; // Var to store LED blinking frequency
void setup() {
Serial.begin(9600);
}
void loop() {
val_intensity = analogRead(potPin_intensity); // read the value from the sensor, between 0 - 1024
val_frequency = analogRead(potPin_frequency); // read the value from the sensor, between 0 - 1024
Serial.print("Intensity: ");
Serial.print(val_intensity / 4);
Serial.print(" Frequency in ms: ");
Serial.println(val_frequency * 4);
analogWrite(ledPin_blue, val_intensity/4); // analogWrite can be between 0-255
delay(val_frequency * 4);
analogWrite(ledPin_blue, 0); // analogWrite can be between 0-255
delay(val_frequency * 4);
}
Pictures