/* Rudolph the red nosed reindeer breathing LED Atmel Studio 7 C Code for the PCBWay Christmas 2017 surprise kit (ATtiny85, 128KHz internal oscillator) Share and enjoy! */ // This must be at most 254 #define PWM_STEPS 64U #define F_CPU 32000UL #include #include void setup(void) { // Rudolph's nose is on PB0 DDRB = 1; // Set clock prescaler 1:4 // Unlock... CLKPR = (1 << CLKPCE); // Set CLKPR = 2; } void pwmCycle(uint8_t onTime) { uint8_t offTime = PWM_STEPS - onTime; while (offTime--) { PORTB &= ~1; } while (onTime--) { PORTB |= 1; } } int main(void) { uint8_t x = 0; setup(); while (1) { for (x = 0; x < PWM_STEPS; ++x) { pwmCycle(x); } for (--x; x < PWM_STEPS; --x) { pwmCycle(x); } _delay_ms(1000); } }