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 static constexpr float speedMultiplier = ctx.lamp.frameDurationMs / 12.0f;
43
44 const uint16_t colorIndex = (ctx.lamp.tick / 4) * speedMultiplier; // Amount of colour change.
45 const float rampIndex = ctx.get_active_custom_ramp() / 255.0f;
46 const float freq = 128 / 4.0f + rampIndex * 16 / 4.0f; // Frequency of the signal.
47
48 ctx.state.step += (speed * speedMultiplier) / 16; // Speed of animation.
49 const float colorIndexNormalised = colorIndex / 255.0f;
50
51 for (size_t i = 0; i < ctx.lamp.ledCount; i++)
52 {
53 // For each of the LED's in the strip, set a brightness based on a wave as follows:
54 // cubicwave8 is 8 bits, so value will be truncated
55 const uint8_t pixBri = cubicwave8((i * freq) + ctx.state.step);
56
57 // get the pixel color from palette
58 const auto pixColor = colors::from_palette((uint8_t)(i * colorIndexNormalised), ctx.state.palette);
59 // blend the pixel color with the black color
60 ctx.lamp.setPixelColor(i, modes::colors::fade<false>(pixColor, pixBri));
61 }
62 }
63};
64
65} // namespace lampda::modes::default_modes
66#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