Skip to content

Commit

Permalink
Add example encoder_input.bitbang for arduino-nano
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Mar 17, 2021
1 parent 47098b9 commit 38ca7a3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/arduino_nano/encoder_input/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021, Thomas Sommer
*
* 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/board.hpp>
#include <modm/processing/timer.hpp>
#include <modm/driver/encoder/encoder_input.hpp>

using namespace modm::platform;

int
main()
{
Board::initialize();
LedD13::setOutput();

modm::Encoder<Board::D7, Board::D8, modm::encoder::Division::FOUR> encoder;

encoder.connect();

int value(0);

modm::ShortPeriodicTimer heartbeat(500ms);
modm::ShortPeriodicTimer encoderUpdate(1ms);
modm::ShortPeriodicTimer outputValue(1000ms);

while (true)
{
if (heartbeat.execute()) Board::LedD13::toggle();
if (encoderUpdate.execute()) encoder.update();
if (outputValue.execute()) {
value += encoder.getValue();
MODM_LOG_INFO << "value: " << x << modm::endl;
}
}
}
11 changes: 11 additions & 0 deletions examples/arduino_nano/encoder_input/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library>
<extends>modm:arduino-nano</extends>
<options>
<option name="modm:build:build.path">../../../../build/arduino_nano/encoder_input</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:processing:timer</module>
<module>modm:driver:encoder_input.bitbang</module>
</modules>
</library>

0 comments on commit 38ca7a3

Please sign in to comment.