Skip to content

Commit

Permalink
[examples] Add STM32F0 ADC example
Browse files Browse the repository at this point in the history
  • Loading branch information
cajt authored and salkinium committed Nov 26, 2018
1 parent 79b6828 commit af2b352
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/nucleo_f042k6/adc/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2016-2017, Niklas Hauser
* Copyright (c) 2017, Nick Sarten
* Copyright (c) 2018, Carl Treudler
*
* 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>

using namespace Board;

typedef GpioInputA0 AdcIn1;

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

Adc::connect<AdcIn1::In0>();
Adc::initialize(Adc::ClockMode::PCLKDividedBy4, Adc::CalibrationMode::DoNotCalibrate);

while (1)
{
LedD13::toggle();
modm::delayMilliseconds(250);

Adc::setPinChannel<AdcIn1>();
Adc::startConversion();
while(!Adc::isConversionFinished()) { }
MODM_LOG_INFO << "ADC A0: " << Adc::getValue() << modm::endl;

}

return 0;
}
10 changes: 10 additions & 0 deletions examples/nucleo_f042k6/adc/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:board:nucleo-f042k6</extends>
<options>
<option name=":build:build.path">../../../build/nucleo_f042k6/adc</option>
</options>
<modules>
<module>:build:scons</module>
<module>:platform:adc</module>
</modules>
</library>

0 comments on commit af2b352

Please sign in to comment.