Tool/software:
I have three sequences programmed into memory. I use one engine to run each of the sequences (never simultaneously).
- Pulsating white program using D1, D2 and D7
- Solid white program (again, D1, D2 and D7)
- Blinking orange program (only D2 and D7)
The sequences work on their own (tested when all outputs were off), but when switching from pulsating or solid sequence to blinking, the mapping seems bugged.
Sometimes the blue LED (D1) will be on and red is blinking (making blue - magenta - blue - magenta...), and sometimes red (D2) and green (D7) are blinking and blue is off (which is as intended!). This behavior seems quite random to me.
Here's my code:
uint8_t mapping_sequence[] = { // Mapping describing which output channels to use (stored in page 0) 0x00, 0x43, // White (Red D2 + Blue D1 and Green D7) 0x00, 0x02, // Red D2 (used for orange) 0x00, 0x40, // Green D7 (used for orange) }; uint8_t pulsating_white_sequence[] = { // Pulsating white program (stored in page 1) 0x9F, 0x80, // Set mapping to instruction 0 0x40, 0x00, // PWM off (all LEDs) 0x40, PULSATING_PWM_HIGHEST, // PWM on PULSATING_CYCLES_PER_STEP | 0x01, PULSATING_PWM_STEPS, // Ramp down PULSATING_WAITING_CYCLES | 0x40, 0x00, // Wait PULSATING_CYCLES_PER_STEP, PULSATING_PWM_STEPS, // Ramp up 0xA0, 0x03, // Jump to instruction 3 }; uint8_t solid_white_program[] = { // Solid white program (stored in page 2) 0x9F, 0x80, // Set mapping to instruction 0 PULSATING_CYCLES_PER_STEP, PULSATING_PWM_STEPS, // Ramp up (smooth transition from pulsing) }; uint8_t blinking_orange_sequence[] = { // Blinking orange program (stored in page 3) 0x9F, 0x80, // Set mapping to instruction 0 0x40, 0x00, // PWM off (all LEDs) 0x9F, 0x81, // Set mapping to instruction 1 0x40, 0x00, // PWM off (Red) 0x9F, 0x82, // Set mapping to instruction 2 0x40, 0x00, // PWM off (Green) BLINKING_WAITING_CYCLES | 0x40, 0x00, // Wait 0x9F, 0x81, // Set mapping to instruction 2 0x40, PWM_RED_ORANGE_BLINKING, // PWM on 0x9F, 0x82, // Set mapping to instruction 3 0x40, PWM_GREEN_ORANGE_BLINKING, // PWM on BLINKING_WAITING_CYCLES | 0x40, 0x00, // Wait 0xA0, 0x02, // Jump to instruction 2 };
The reason for the separate mappings for red and green (to make orange) is because I want the PWM/brightness value of both to be separately manageable, giving full control over the color that is seen.
Is something wrong with my code, or is my code bad practice or something?