And here is list of components:
- Supercapacitor 0.1 F, 5.5 V (NEC)
- Attiny85 microchip
- Red-Green bi-color LED (5mm)
- Resistor 180 Ohm, 0.125 W
- Diode Schottky ( 1N5817) (for this test it is not really needed but later I will utilize it to detect the moment when external power is down).
Circuit initially powered up by 5V USB 0.5 A power supply.
Code is short, so I put it here as well.
#include <avr/io.h> #define F_CPU 1000000UL #include <util/delay.h> typedef enum {OUT_LOW, OUT_HIGH} OutputLevel; #define pinOut(bit, outLevel) \ (DDRB |= (1 << ( DDB##bit)));\ switch(outLevel) \ {\ case OUT_LOW: (PORTB &= ~(1 << (DDB##bit))); break;\ case OUT_HIGH: (PORTB |= (1 << (DDB##bit))); break;\ } int main(void) { while (1) { pinOut(0,OUT_LOW); pinOut(2,OUT_HIGH); _delay_ms(200.0); pinOut(0,OUT_HIGH); pinOut(2,OUT_HIGH); _delay_ms(800.0); pinOut(0,OUT_HIGH); pinOut(2,OUT_LOW); _delay_ms(200.0); pinOut(0,OUT_HIGH); pinOut(2,OUT_HIGH); _delay_ms(800.0); } }
No comments:
Post a Comment