-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (48 loc) · 1.18 KB
/
main.cpp
File metadata and controls
57 lines (48 loc) · 1.18 KB
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
/*
* Copyright (c) 2010-2011, Fabian Greif
* Copyright (c) 2013-2014, 2016-2017, Niklas Hauser
* Copyright (c) 2014, Sascha Schade
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------
#include <modm/platform.hpp>
#include <modm/architecture/interface/interrupt.hpp>
#include <modm/ui/button_group.hpp>
using namespace modm::platform;
static modm::ButtonGroup<> buttons(0);
enum
{
BUTTON_1 = 0x01
};
typedef GpioOutputB0 Led;
typedef GpioInputB3 Button;
// Timer interrupt used to query the button status
MODM_ISR(TIMER2_COMPA)
{
buttons.update(Button::read() ? BUTTON_1 : 0);
}
int
main()
{
Led::setOutput();
Led::reset();
TCCR2A = (1 << WGM21);
TCCR2B = (1 << CS22);
TIMSK2 = (1 << OCIE2A);
OCR2A = 23; // 10 ms at 14.7456 MHz
// set PB3 as input with pullup
Button::setInput(Gpio::InputType::PullUp);
enableInterrupts();
while (true)
{
if (buttons.isPressed(BUTTON_1))
{
Led::toggle();
}
}
}