Concept
The concept of this project is to create an system can make light of any colour using rgb values. In the last class we learnt about analogue and digital input and output. Using this concept, I created a circuit that uses analogue input to control the brightness of a red, green and blue led to obtain a specific color, just as we could pick specific colors when coding in p5js.
A photo-resistor, potentiometer and push switch are used to control the rgb values of the LEDs and the lights were physically merged together so as to give the idea they were producing one light of a specified color.
Sketch
Code
// A0 = Potentiometer input
// A1 = Photoresistor input
// A2 = Push switch input
// 3 = Blue LED to resistor to GND
// 5 = Green LED to resistor to GND
// 7 = Red LED to resistor to GND
void setup() {
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(7, OUTPUT);
// flash all LEDs
digitalWrite(3, HIGH);
digitalWrite(5, HIGH);
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(7, LOW);
}
void loop() {
int potentiometer = analogRead(A0);
int photoresistor = analogRead(A1);
int pSwitch = digitalRead(A2);
int pm = map(potentiometer, 0, 1023, 0, 255);
int pr = map(photoresistor, 0, 1023, 155, 255);
analogWrite(3, pr);
analogWrite(5, pm);
digitalWrite(7, pSwitch);
}
How It’s made
A potentiometer, photo resistor and a push switch were connected to 5V terminal. The analog input of each of these devices were read by the analog in pins A0, A1 and A2. LEDs were connected to pins 3, 5 and 7. The inputs from the potentiometer, photo resisters and push switches can be tuned to obtain the desired effect.
Physical Circuit
Digital Circuit
Reflection
This work was really fun to create. I enjoyed playing around with analog inputs and outputs. Possible improvements in the future are including codes to cause some flashing effects to show different color and state. More analog inputs can be included also to create different physical effects. More LEDs can also be added to create more visual effects.


