ATTINY85 – flash multiple LEDs

Similar to our previous example when we flashed a single LED, in this case we connect 3 LEDs up to Pin 5, 6 and 7 which are PB0,1 and 2. We will then flash 3 LEDs

Here is the schematic for this example

Schematic

attiny85 three LEDs

attiny85 three LEDs

Source

Again this was written in Atmel Studio

 

  1. #include <avr/io.h>
  2. #define F_CPU 1000000UL
  3. #include <util/delay.h>
  4. int main (void)
  5. {
  6. // port B pins 0, 1, 2 as output
  7. DDRB = (1 << PB2) | (1 << PB1) | (1 << PB0);
  8.  
  9. unsigned int i = 0;
  10. while(1)
  11. {
  12. PORTB = i & ( (1 << PB2) | (1 << PB1) | (1 << PB0) );
  13.  
  14. i = (i+1) % 8;
  15.  
  16. _delay_ms( 500 );
  17. }
  18. }

 

 

Links

 

Free shipping 10PCS ATTINY85