diff --git a/examples/samv71_xplained_ultra/mcp3008/main.cpp b/examples/samv71_xplained_ultra/mcp3008/main.cpp new file mode 100644 index 0000000000..b2ad1d2c16 --- /dev/null +++ b/examples/samv71_xplained_ultra/mcp3008/main.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023, Christopher Durand + * + * 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 + +using namespace Board; +using namespace modm::platform; + +using SpiMaster = SpiMaster0; +using Sck = GpioD22; +using Mosi = GpioD21; +using Miso = GpioD20; +using Cs = GpioD25; + +int main() +{ + Board::initialize(); + + MODM_LOG_INFO << "MCP3004/8 ADC example" << modm::endl; + + SpiMaster::connect(); + Cs::setOutput(true); + + SpiMaster::initialize(); + + modm::Mcp3008 adc; + adc.initialize(); + + constexpr std::array channels = { + std::make_pair(0, modm::mcp3008::Channel::Ch0), + std::make_pair(1, modm::mcp3008::Channel::Ch1), + std::make_pair(2, modm::mcp3008::Channel::Ch2), + std::make_pair(3, modm::mcp3008::Channel::Ch3) + }; + + while (true) { + for (auto [i, ch] : channels) { + const auto value = RF_CALL_BLOCKING(adc.read(ch)); + MODM_LOG_INFO << "channel " << i << ": " << value << '\n'; + } + + Led0::toggle(); + Led1::toggle(); + modm::delay(1s); + } + + return 0; +} diff --git a/examples/samv71_xplained_ultra/mcp3008/project.xml b/examples/samv71_xplained_ultra/mcp3008/project.xml new file mode 100644 index 0000000000..6d11a839de --- /dev/null +++ b/examples/samv71_xplained_ultra/mcp3008/project.xml @@ -0,0 +1,11 @@ + + modm:samv71-xplained-ultra + + + + + modm:build:scons + modm:driver:mcp3008 + modm:platform:spi:0 + +