// RGBLED on ATtiny85
// Reference material: https://www.engineersgarage.com/?s=attiny85
#define rPin 1 // PB1 - Pin 6 - PWM
#define gPin 0 // PB0 - Pin 5 - PWM
#define bPin 4 // PB4 - Pin 3 - PWM
#define vMax 255 // Maximum brightness
#define vMin 0 // Minimum brightness
#define dTime 10 // fading time between colors
int rVal;
int gVal;
int bVal;
float counter = 0;
void setup() {
pinMode(rPin, OUTPUT); // configure I/O pin
pinMode(gPin, OUTPUT); // configure I/O pin
pinMode(bPin, OUTPUT); // configure I/O pin
}
void loop() {
// crossfade();
// fadeup(); // one color
fadeupdown(); // one color
}
void fadeup() {
for (int i = 0; i < 255; i += 5) { // fade from off to max
int rVal = i;
analogWrite(rPin, rVal);
delay(50);
}
}
void fadeupdown() {
rVal = 128;
gVal = 0;
bVal = 128; // PB4 does not like being the only color
analogWrite(rPin, rVal); // Write the PWM value to the LED
analogWrite(gPin, gVal); // Write the PWM value to the LED
analogWrite(bPin, bVal); // Write the PWM value to the LED
}
void crossfade() {
counter = counter + 1;
rVal = sin(counter / 100 + PI * 0 / 3) * 1000;
gVal = sin(counter / 100 + PI * 2 / 3) * 1000;
bVal = sin(counter / 100 + PI * 4 / 3) * 1000;
rVal = map(rVal, -1000, 1000, 0, 255);
gVal = map(gVal, -1000, 1000, 0, 255);
bVal = map(bVal, -1000, 1000, 0, 255);
analogWrite(rPin, rVal);
analogWrite(gPin, gVal);
analogWrite(bPin, bVal);
delay(5);
}
/************************************************************************************************
ATTINY85 +-- --+
PCINT5/-RESET/ADC0/dW/PB5 |1 * 8| VCC
PCINT3/XTAL1/CLKI/-OC1B/ADC3/PB3 |2 7| PB2/SCK/USCK/SCL/ADC1/T0/INT0/PCINT2
PWM4/PCINT4/XTAL2/CLKO/OC1B/ADC2/PB4 |3 6| PB1/MISO/DO/AIN1/OC0B/OC1A/PCINT1/PWM1
GND |4 5| PB0/MOSI/DI/SDA/AIN0/OC0A/-OC1A/AREF/PCINT0/PWM0
+-----+
************************************************************************************************/