Subversion Repositories Projects

Rev

Rev 426 | Details | Compare with Previous | Last modification | View Log | RSS feed

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