-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (61 loc) · 1.8 KB
/
main.cpp
File metadata and controls
71 lines (61 loc) · 1.8 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (c) 2011, Georgi Grinshpun
* Copyright (c) 2011-2012, Fabian Greif
* Copyright (c) 2012-2014, Sascha Schade
* Copyright (c) 2013-2014, Kevin Läufer
* Copyright (c) 2013, 2015-2018, Niklas Hauser
*
* 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/.
*/
// ----------------------------------------------------------------------------
/**
* This example is to demonstrate the External Interrupt (EXTI)
*
* The red/green LEDs toggles by busy waiting.
* When the button is pressed the blue LED flashes
* for a very short moment in the interrupt handler.
*
*/
#include <modm/board.hpp>
#include <modm/architecture/interface/interrupt.hpp>
using namespace Board;
using Irq = GpioInputE11;
// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();
// will be used to indicate external interrupts
LedOrange::setOutput(modm::Gpio::Low);
LedBlue::setOutput(modm::Gpio::Low);
// will be toggled to indicate that the program is still running
LedGreen::setOutput(modm::Gpio::Low);
LedRed::setOutput(modm::Gpio::High);
// push the button to see the blue led light up
Button::setInput(Gpio::InputType::Floating);
Exti::connect<Button>(Exti::Trigger::RisingEdge, [](uint8_t)
{
LedBlue::set();
modm::delay(1ms);
LedBlue::reset();
});
// pull pin E11 low to see the orange led light up
Irq::setInput(Gpio::InputType::PullUp);
Exti::connect<Irq>(Exti::Trigger::BothEdges, [](uint8_t)
{
LedOrange::set();
modm::delay(1ms);
LedOrange::reset();
});
while (true)
{
LedRed::toggle();
LedGreen::toggle();
modm::delay(500ms);
}
return 0;
}