NaMaLiCS Tutorial Part 5, D_LOOP

  • WRTyler
  • -the National Mall guy-
  • wrTyler
  • updated 2 yrs ago

This the control center for the NaMaLiCS program. There are two sections in the loop.  The first controls how the lights initially turn on (toggle, fade or flicker) and the second controls what happens after they are on (an occasional flicker or dimming).

The code below produces this set of lighting effects.

 

  • Pixel 1 - flickers on after a delay of 1 second then stays on
  • Pixel 2 - fades on after a delay of 1 second and then stays on
  • Pixel 3 - fades on after a delay of 1.5 seconds and then stays on
  • Pixel 4 - is off and then will flicker occasionally
  • Pixel 5 - toggles on after a delay of 4 seconds and then stays on
  • Pixel 6 - fades on after a delay of 3 seconds and then will flicker occasionally
  • Pixel 7 - fades on after a delay of 3.5 seconds and then stays on
  • Pixel 8 - fades on after a delay of 4 seconds and then stays on
  • Pixel 9 - starts blinking immediately and keeps blinking
// This loops forever as long as the program is running

void loop() {
  // Refresh the current time each time through the loop
  //  used to calculate the timing needed to trigger events
  //  or the duration of an effect
  currentMillis = millis();

  // Have all the pixels finished thier initial light effect
  //  if not, execute the code in this section
  if( pixelState != allPixelsOn )
  {
    // First value is which pixel has the effect
    //  Second value is how much delay before the effect starts
    flickerOn( 1, 1000 );
    fadeOn( 2, 1000 );
    fadeOn( 3, 1500 );
    toggleOff( 4, 0 );
    toggleOn( 5, 4000 );
    fadeOn( 6, 3000 );
    fadeOn( 7, 3500 );
    fadeOn( 8, 4000 );
    blinkPixel( 9, 0 );
  }
  // If all the pixels have finished their initial effect
  //  go into the long term maintenance mode pixel effects
  else
  {

    // Pixel #4 is usually off, but has occasional flickers
    if( flickerSwitch01 == false ) flickerPixel( 4, 0 );
    if( flickerSwitch01 == true ) toggleOff( 4, 0 );

    // Pixel #6 is usually on, but has occasional flickers
    if( flickerSwitch02 == false ) flickerPixel( 6, 0 );
    if( flickerSwitch02 == true ) toggleOn( 6, 0 );

    // Flicker rate #1 - this flicker happens every 4 seconds
    if( currentMillis - flickerMillis01 >= flickerInterval01 ) {
      flickerSwitch01 = !flickerSwitch01;
      flickerMillis01 = millis();
    }
    // Flicker rate #2 - this flicker happens every 2.5 seconds
    if( currentMillis - flickerMillis02 >= flickerInterval02 ) {
      flickerSwitch02= !flickerSwitch02;
      flickerMillis02 = millis();
    }

    // Continue to blink Pixel #9 that was started in the first
    //  section
    blinkPixel( 9, 0 );
  }

  // After the brightness settings for all the pixels have
  //  been calculated, send the information to the hardware
  pixels.show();
}

Next, we are going to revisit the B_GLOBALS and discuss pixelState, a solution for knowing when all the pixels have finished their initial lighting effect.

-wrtyler-

Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like1 Follow
  • 1 Likes
  • 2 yrs agoLast active
  • 14Views
  • 1 Following