So guys, i set myself one heck of a challenge (for me at least) and its something the lecturers at my uni in electronics have never seen before.
The premise of my challenge is simply to change the colour of a strip of RGB LEDs with one potentiometer, that part is fine, (and bench tested it using the hardware, an arduino and breadboard)
I have researched and tried to understand the code that i have found elsewhere on the interballs (to change the colour ect ect) but cant get my head around it.
If someone could please help me to understand and condense the code id be very grateful.
I wanted to condense it so made a pcb that takes power in, uses an attiny 24 as the computational brain, then outputs straight to the LED strip.
Ive managed to write to the board and have a blink program setup to run (and it works great) but when i tried to upload the file to the attiny it was reading that the code was too large.
The below is the code i would like to use but am not sure how to condense it further but keep the function of it the same, thanks in advance.
"
/*
- Code for making one potentiometer control 3 LEDs, red, grn and blu, or one tri-color LED
- The program cross-fades from red to grn, grn to blu, and blu to red
- Clay Shirky clay.shirky@nyu.edu
*/
// INPUT: Potentiometer should be connected to 5V and GND
int potPin = 3; // Potentiometer output connected to analog pin 3
int potVal = 0; // Variable to store the input from the potentiometer
// OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins
// LED's cathodes should be connected to digital GND
int redPin = 9; // Red LED, connected to digital pin 9
int grnPin = 10; // Green LED, connected to digital pin 10
int bluPin = 11; // Blue LED, connected to digital pin 11
// Program variables
int redVal = 0; // Variables to store the values to send to the pins
int grnVal = 0;
int bluVal = 0;
void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
}
// Main program
void loop()
{
potVal = analogRead(potPin); // read the potentiometer value at the input pin
if (potVal < 341) // Lowest third of the potentiometer's range (0-340)
{
potVal = (potVal * 3) / 4; // Normalize to 0-255
redVal = 256 - potVal; // Red from full to off
grnVal = potVal; // Green from off to full
bluVal = 1; // Blue off
}
else if (potVal < 682) // Middle third of potentiometer's range (341-681)
{
potVal = ( (potVal-341) * 3) / 4; // Normalize to 0-255
redVal = 1; // Red off
grnVal = 256 - potVal; // Green from full to off
bluVal = potVal; // Blue from off to full
}
else // Upper third of potentiometer"s range (682-1023)
{
potVal = ( (potVal-683) * 3) / 4; // Normalize to 0-255
redVal = potVal; // Red from off to full
grnVal = 1; // Green off
bluVal = 256 - potVal; // Blue from full to off
}
analogWrite(redPin, redVal); // Write values to LED pins
analogWrite(grnPin, grnVal);
analogWrite(bluPin, bluVal);
}
"
EDIT
Note this is not my code but the code i have found and would like to use / modify to work in my scenario