Fast Led Multiple Colour Pallets in a State Machine

Good Afternoon,

I am working on a project using the WSB2812B LED strip, with a ATmega644A using the MCUdude/MightyCore plug in (GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535). I am using Fastled 3.3.3 with Ardunio 1.8.13 on Windows 10 and is using code based off "ColourWavesWithPalettes" (ColorWavesWithPalettes - demo of using cpt-city palettes in FastLED code · GitHub).

This project as 2 button inputs (Solid & Palette colour) and 2 outputs (LED DI & Mosfet gate). With the sequence being the following:

  1. Power on and start running a set of colour palettes with fade (STANDARD_COLOUR_PALETTE). This could be anything from 5-15 colours, with transitioning colours from red to green to blue to purple to yellow... etc .
  2. If "Palette colour" button is pressed, then change state to run 1 colour palette with fade (SINGLE_COLOUR_PALETTE) on repeat. E.G just purple with fade.
  3. While in SINGLE_COLOUR_PALETTE state, if "Palette colour" button is pressed then change colour to another 1 colour palette e.g blue but still in the SINGLE_COLOUR_PALETTE state.
  4. If in either "STANDARD_COLOUR_PALETTE" or "SINGLE_COLOUR_PALETTE" state and "Solid" button is pressed, then change state to run 1 solid colour (SOLID_COLOUR) e.g just blue with no fade.
  5. While in "STANDARD_COLOUR_PALETTE" if "Solid" button is pressed, then change to another solid colour e.g Red with no fade.
  6. While in "STANDARD_COLOUR_PALETTE" if "Palette colour" button is pressed then change state to colour palettes with fade (STANDARD_COLOUR_PALETTE).

In summary the code is made up of 3 states with for loops and if statements. I have most of this sequence working but I am struggling alot with step 2 & 3, as their is only 1 colour pallet "Playlist" that I am trying to use as STANDARD_COLOUR_PALETTE but also trying to pull induvial colour pallets from (SINGLE_COLOUR_PALETT).

One solution I thought of was to generate multiple separate a colour playlists one with the 5-15 colours that would fade to one another and many more that would just have the single colour pallet. The only issue is that I don't know how to code that into the exiting "ColourWavesWithPalettes" I used as a base.

My code is attached here: State Machine With Colour Palettes · GitHub

Any help would be greatly appreciated.

Thanks,

seems you have 2 display modes: Standard and Single. not sure if there are sub-modes or maybe there are more than 2 mode

it would make sense to have separate routines for each mode that are called within loop() depending on which mode is active

within loop() and depending on the mode, the buttons may have different meanings either changing the mode or changing what is display (e.g. color) is displayed in the current mode (w/o changing the mode)

having sub-functions make it easier to understand the code isolating functionality

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.