diff options
Diffstat (limited to 'src/device/main.ino')
-rw-r--r-- | src/device/main.ino | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/device/main.ino b/src/device/main.ino new file mode 100644 index 0000000..b028d17 --- /dev/null +++ b/src/device/main.ino @@ -0,0 +1,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; +} |