Skip to content

Commit

Permalink
[examples] Add WS2812 example
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Apr 6, 2019
1 parent 0f403ea commit b61e030
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ make gdb

## Interesting Examples

We have a lot of examples, <!--examplecount-->169<!--/examplecount--> to be
We have a lot of examples, <!--examplecount-->170<!--/examplecount--> to be
exact, but here are some of our favorite examples for our supported development
boards:

Expand Down
52 changes: 52 additions & 0 deletions examples/nucleo_f411re/ws2812b/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2019, 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>
#include <modm/driver/pwm/ws2812b.hpp>
#include <modm/ui/led/tables.hpp>
#include <modm/processing/timer.hpp>

using namespace Board;

using Output = Board::D11;
modm::Ws2812b<SpiMaster1, Output, 8*8> leds;
modm::ShortPeriodicTimer tmr{33};

int
main()
{
Board::initialize();
LedD13::setOutput();
leds.initialize<Board::SystemClock>();

constexpr uint8_t max = 62;
uint8_t r=0, g=max/3, b=max/3*2;

while (1)
{
for (size_t ii=0; ii < leds.size; ii++)
{
leds.setColor(ii,
modm::ui::table22_8_256[r*3/2],
modm::ui::table22_8_256[g*3/2],
modm::ui::table22_8_256[b*3/2]);
if (r++ >= max) r = 0;
if (g++ >= max) g = 0;
if (b++ >= max) b = 0;
}
leds.write();

while(not tmr.execute()) ;
LedD13::toggle();
}

return 0;
}
13 changes: 13 additions & 0 deletions examples/nucleo_f411re/ws2812b/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<library>
<extends>modm:nucleo-f411re</extends>
<options>
<option name=":build:build.path">../../../build/nucleo_f411re/ws2812b</option>
</options>
<modules>
<module>:driver:ws2812</module>
<module>:platform:spi:1</module>
<module>:ui:led</module>
<module>:build:scons</module>
</modules>
</library>

0 comments on commit b61e030

Please sign in to comment.