Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* ATTINY85-LED-Boost.c
* Full article at
* http://wp.josh.com/2017/03/20/blinking-blue-powering-a-3-7-volt-blue-led-from-a-2-4-volt-coin-cell-with-a-0-02-charge-pump
*
*/
#include <avr/io.h>
#define F_CPU 1000000 // 1MHz, default for 8MHz internal osc and clkdiv8
#include <util/delay.h>
int main(void)
{
DDRB |= _BV(0); // Pin 5 = Output
while (1) // Blink forever at about 5Hz (100ms oscillating, 100ms off)
{
// This top section oscillates pin 5 at about for about 100ms
for(int i=0; i<10*100;i++ ) { // Each loop pass takes about 100us, so this for() will take ~100ms
// This is a 10KHz (50us high, 50us low) oscillator on pin 5
PORTB |= _BV(0);
_delay_us(50);
PORTB &= ~_BV(0);
_delay_us(50);
}
// This leaves pin 5 low for 100ms
_delay_ms(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment