Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
426 killagreg 1
#include "timer0.h"
2
#include "button.h"
3
 
4
 
5
#ifdef USE_FOLLOWME
6
#define BUTTON       !(PINC & (1<<PINC6))
7
#endif
8
#ifdef USE_SDLOGGER
9
#define BUTTON       !(PINC & (1<<PINC3))
10
#endif
11
 
12
#define CNT_KEY     10 // at least 3
13
#define KEY_DELAY_MS  50
14
 
15
uint16_t ButtonTimer = 0;
16
 
17
void Button_Init(void)
18
{
19
 
20
        // set port pin as input pullup
21
        #ifdef USE_FOLLOWME
22
        PORTC |= (1 << PORTC6);
23
        DDRC &= ~(1 << DDC6);
24
        #endif
25
 
26
        #ifdef USE_SDLOGGER
27
        PORTC |= (1 << PORTC3);
28
        DDRC &= ~(1 << DDC3);
29
        #endif
30
        ButtonTimer = SetDelay(KEY_DELAY_MS);
31
}
32
 
33
uint8_t GetButton(void)
34
{
35
        static uint8_t button = 0;
36
        uint8_t ret = 0;
37
 
38
        if(CheckDelay(ButtonTimer))
39
        {
40
                if(BUTTON)
41
                {
42
                        if(button++ == 0 || button == CNT_KEY) ret = 1;
43
                        if(button == CNT_KEY) button = CNT_KEY - CNT_KEY / 3;
44
                }
45
                else button = 0;
46
                ButtonTimer = SetDelay(KEY_DELAY_MS);
47
        }
48
        return(ret);
49
}
50