diff --git a/examples/rp_pico/adc_simple/main.cpp b/examples/rp_pico/adc_simple/main.cpp new file mode 100644 index 0000000000..5fd4bb676e --- /dev/null +++ b/examples/rp_pico/adc_simple/main.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022, Nikolay Semenov + * + * 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 +#include +#include + +int +main() +{ + Board::initialize(); + + using Led = Board::LedGreen; + Led::setOutput(true); + + Uart0::connect(); + Uart0::initialize(); + + modm::IODeviceWrapper loggerDevice; + modm::IOStream out(loggerDevice); + + Adc::connect(); + Adc::initialize(); + Adc::enableTemperatureSensor(); + + while (true) + { + out.printf("---\r\n"); + for (uint8_t ch = 0; ch < (uint8_t)Adc::Channel::Ch3; ++ch) + { + auto value = Adc::readChannel((Adc::Channel)ch); + out.printf("ADC Channel %u %f V | 0x%04x %u\r\n", ch, Adc::convertToVoltage(value), + value, value); + } + { + auto value = Adc::readChannel(Adc::Channel::Ch3); + out.printf("ADC VSYS %f V | 0x%04x %u\r\n", 3.f * Adc::convertToVoltage(value), + value, value); + } + { + auto value = Adc::readChannel(Adc::Channel::Temperature); + out.printf("ADC Int Temp %.4f C | 0x%04x %u\r\n", Adc::convertToTemperature(value), + value, value); + } + modm::delay(250ms); + Led::toggle(); + } + + return 0; +} diff --git a/examples/rp_pico/adc_simple/project.xml b/examples/rp_pico/adc_simple/project.xml new file mode 100644 index 0000000000..6aee18e673 --- /dev/null +++ b/examples/rp_pico/adc_simple/project.xml @@ -0,0 +1,12 @@ + + modm:rp-pico + + + + + modm:io + modm:platform:adc + modm:platform:uart:0 + modm:build:scons + +