Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
sine_mode.hpp
Go to the documentation of this file.
1#ifndef SINE_MODE_H
2#define SINE_MODE_H
3
6
9
11
16{
18 static constexpr uint8_t speed = 128;
19
21 static constexpr bool hasCustomRamp = true;
22
23 struct StateTy
24 {
26 uint16_t step;
29 };
30
31 static void on_enter_mode(auto& ctx)
32 {
33 ctx.state.step = 0;
34 ctx.state.palette = colors::PaletteRainbowColors;
35
36 // the ramp will not return to 0 after reach 255 (and the oposite)
37 ctx.template set_config_bool<ConfigKeys::rampSaturates>(true);
38 }
39
40 static void loop(auto& ctx)
41 {
42 const uint16_t colorIndex = ctx.lamp.tick / 4; // Amount of colour change.
43 const float rampIndex = ctx.get_active_custom_ramp() / 255.0;
44 const float freq = 128 / 4.0 + rampIndex * 16 / 4.0; // Frequency of the signal.
45
46 ctx.state.step += speed / 16; // Speed of animation.
47 const float colorIndexNormalised = colorIndex / 255.0;
48
49 for (size_t i = 0; i < ctx.lamp.ledCount; i++)
50 {
51 // For each of the LED's in the strip, set a brightness based on a wave as follows:
52 // cubicwave8 is 8 bits, so value will be truncated
53 const uint8_t pixBri = cubicwave8((i * freq) + ctx.state.step);
54
55 // get the pixel color from palette
56 const auto pixColor = colors::from_palette((uint8_t)(i * colorIndexNormalised), ctx.state.palette);
57 // blend the pixel color with the black color
58 ctx.lamp.setPixelColor(i, modes::colors::fade<false>(pixColor, pixBri));
59 }
60 }
61};
62
63} // namespace lampda::modes::default_modes
64#endif
Manipulate color representations.
static constexpr uint32_t from_palette(UIntTy index, const PaletteTy &palette, uint8_t brightness=255)
Return a color from a palette.
Definition: palettes.hpp:504
std::array< uint32_t, 16 > PaletteTy
Palette types.
Definition: palettes.hpp:18
static constexpr PaletteTy PaletteRainbowColors
HSV Rainbow.
Definition: palettes.hpp:360
Basic "default" modes included with the hardware.
Definition: aurora.hpp:12
Define some useful color palettes, and tools to use them.
Parent object for all custom user modes.
Definition: mode_type.hpp:53
colors::PaletteTy palette
color palette to use
Definition: sine_mode.hpp:28
uint16_t step
step of the animation
Definition: sine_mode.hpp:26
Barber shop sign looking animation, with nice swirl effect.
Definition: sine_mode.hpp:16
static constexpr bool hasCustomRamp
User ramp change the frequency of the mode.
Definition: sine_mode.hpp:21
static constexpr uint8_t speed
speed of the animation
Definition: sine_mode.hpp:18