1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*
* Usurpation – wearable device main logic
*
* Copyright (C) 2019 Gediminas Jakutis
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdlib.h>
static const unsigned int internal_led = 2;
unsigned int toggleled(void);
void setup(void)
{
pinMode(internal_led, OUTPUT);
/* don't set pin mode here, it will get toggled at the very start of
* the logic loop, either way.
*/
}
/* the logic is a placeholder right now */
void loop(void)
{
/* sleep length to use */
static unsigned int delta = 100;
/* progresivelly grow the time delta while changing state*/
delta += delta >> (6 + toggleled());
/* sleep */
delay(delta);
}
/* toggle the bult-in led and return current state */
unsigned int toggleled(void)
{
static unsigned int state = 0;
state = !state;
/* as the cathode of the builtin diode is connected to the MCU's pin,
* while the anode is connected to Vcc, to turn it off, we need to set
* the pin to HIGH.
*/
digitalWrite(internal_led, state ? LOW : HIGH);
return state;
}
|