Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evanrinehart/a6387e4af8c7857c33e12ddbf40acf73 to your computer and use it in GitHub Desktop.
Save evanrinehart/a6387e4af8c7857c33e12ddbf40acf73 to your computer and use it in GitHub Desktop.
// code is for 16MHz adafruit trinket (atmel ATtiny85)
int red = 0;
int green = 1;
int blue = 2;
void setup() {
// put your setup code here, to run once:
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}
int t[3] = {0,0,0};
int permil[3] = {0,0,0};
int light[3] = {red,green,blue};
int timer[3] = {0,0,0};
int dir[3] = {1,1,1};
int rate[3] = {800,600,1100};
int flicker_max[3] = {400,400,400};
int attenuation[3] = {400,400,50};
int steps[3] = {4,4,1};
void manageLight(int i){
/* duty cycle determines instantaneous brightness */
t[i]++;
if(t[i] < permil[i]){
digitalWrite(light[i], HIGH);
}
else if(t[i] < flicker_max[i]){
digitalWrite(light[i], LOW);
}
else{
t[i] = 0;
}
/* second, slower timer controls duty cycle bounce */
timer[i]++;
if(timer[i] > rate[i]){
timer[i] = 0;
permil[i] += dir[i] * steps[i];
if(permil[i] == attenuation[i] || permil[i] == 0) dir[i] *= -1;
}
}
void loop() {
manageLight(0);
manageLight(1);
manageLight(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment