-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (39 loc) · 1.28 KB
/
main.cpp
File metadata and controls
46 lines (39 loc) · 1.28 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
/*
* Copyright (c) 2013, Kevin Läufer
* Copyright (c) 2013-2014, Sascha Schade
* Copyright (c) 2013-2017, 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/.
*/
// ----------------------------------------------------------------------------
#include <modm/board.hpp>
// ----------------------------------------------------------------------------
typedef GpioInputB12 AdcIn0;
// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();
// initialize Adc4
Adc4::initialize(Adc4::ClockMode::Asynchronous, Adc4::Prescaler::Div256,
Adc4::CalibrationMode::SingleEndedInputsMode, true);
Adc4::connect<AdcIn0::In3>();
Adc4::setPinChannel<AdcIn0>(Adc4::SampleTime::Cycles182);
while (true)
{
Adc4::startConversion();
// wait for conversion to finish
while(!Adc4::isConversionFinished());
// print result
int adcValue = Adc4::getValue();
MODM_LOG_INFO << "adcValue=" << adcValue;
float voltage = adcValue * 3.3 / 0xfff;
MODM_LOG_INFO << " voltage=" << voltage << modm::endl;
modm::delay(500ms);
}
return 0;
}