]> www.fi.muni.cz Git - bike-lights.git/blob - gpio.c
ambient light sensor
[bike-lights.git] / gpio.c
1 #include <avr/io.h>
2
3 #include "lights.h"
4
5 void gpio_init()
6 {
7         DDRB |= _BV(PB2) | _BV(PB4);
8         PORTB &=~ (_BV(PB2) | _BV(PB4));
9 }
10
11 void gpio_set(unsigned char n, unsigned char on)
12 {
13         unsigned char bits = 0;
14         switch(n) {
15         case GPIO_LED1: bits = _BV(PB4); break;
16         case GPIO_LED2: bits = _BV(PB2); break;
17         }
18
19         if (on) {
20                 PORTB |= bits;
21         } else {
22                 PORTB &= ~bits;
23         }
24 }
25