/********************************************* * Author: Leah Buechley * Filename: blink.c * Chip: ATtiny13 */ #define F_CPU 1000000 #include #include #include "../leah_library/pin_macros.h" int main (void) { b0Output(); // these are LEDs b1Output(); b2Output(); b4Output(); b3Input(); // this is the switch // to get fading for b0 and b1 TCCR0A |= (1 << WGM00); // phase correct pwm TCCR0A |= (1 << COM0A1); // non-inverting mode TCCR0A |= (1 << COM0B1); // non-inverting mode TCCR0B |= (1 << CS01); // prescale factor of 8 int i; int high = 0; for (;;) { if (b3IsLow()) { //turn on non-pwm lights b2High(); b4High(); i = 255; //keep pwm lights fading on and off while(b3IsLow()) { OCR0A = i; // set duty cycle OCR0B = i; if (i == 255) { high = 1; } else if (i == 0) { high = 0; } if (high==1) { i--; } else { i++; } _delay_ms(10); } } else { OCR0A = 0; OCR0B = 0; b2Low(); b4Low(); } } return 0; }