|
| 1 | +/* |
| 2 | + * Copyright (c) 2019, Niklas Hauser |
| 3 | + * Copyright (c) 2023, Henrik Hose |
| 4 | + * |
| 5 | + * This file is part of the modm project. |
| 6 | + * |
| 7 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 8 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 9 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 10 | + */ |
| 11 | +// ---------------------------------------------------------------------------- |
| 12 | + |
| 13 | +#include <modm/board.hpp> |
| 14 | +#include <modm/driver/pwm/ws2812b.hpp> |
| 15 | +#include <modm/ui/led/tables.hpp> |
| 16 | +#include <modm/processing/timer.hpp> |
| 17 | +#include <modm/processing.hpp> |
| 18 | + |
| 19 | +using namespace Board; |
| 20 | + |
| 21 | +using Output = Board::D11; |
| 22 | +using DmaRx = Dma1::Channel3; |
| 23 | +using DmaTx = Dma1::Channel4; |
| 24 | +using SpiLed = SpiMaster2_Dma<DmaRx, DmaTx>; |
| 25 | +// using SpiLed = SpiMaster2; // for non-dma version |
| 26 | +modm::Ws2812b<SpiLed, Output, 8*8> leds; |
| 27 | +modm::ShortPeriodicTimer tmr{33ms}; |
| 28 | + |
| 29 | +constexpr uint8_t max = 62; |
| 30 | +uint8_t r=0, g=max/3, b=max/3*2; |
| 31 | + |
| 32 | +int |
| 33 | +main() |
| 34 | +{ |
| 35 | + Board::initialize(); |
| 36 | + LedD13::setOutput(); |
| 37 | + Dma1::enable(); |
| 38 | + leds.initialize<Board::SystemClock>(); |
| 39 | + |
| 40 | + constexpr uint8_t max = 60; |
| 41 | + uint8_t r=0, g=max/3, b=max/3*2; |
| 42 | + |
| 43 | + while (true) |
| 44 | + { |
| 45 | + for (size_t ii=0; ii < leds.size; ii++) |
| 46 | + { |
| 47 | + leds.setColor(ii, |
| 48 | + {modm::ui::table22_8_256[r*3/2], |
| 49 | + modm::ui::table22_8_256[g*3/2], |
| 50 | + modm::ui::table22_8_256[b*3/2]}); |
| 51 | + if (r++ >= max) r = 0; |
| 52 | + if (g++ >= max) g = 0; |
| 53 | + if (b++ >= max) b = 0; |
| 54 | + } |
| 55 | + leds.write(); |
| 56 | + |
| 57 | + while(not tmr.execute()) ; |
| 58 | + LedD13::toggle(); |
| 59 | + } |
| 60 | + |
| 61 | + return 0; |
| 62 | +} |
0 commit comments