What a difference a year makes!!
I'm changing my old NaMaLiCS code over from using the Brickstuff Arduino shield
and Adafruit NeoPixel code to a new custom SmartPixel board. These test boards are directly accessible from the Arduino. The code difference is shown below. (You're going to need to scroll a ways to get through the NeoPixel code.)
Cleaner, shorter, easier to understand. I'm really excited about the potential of this product. For my National Mall project, it will make creating and controlling the Lighting Control System easier to assemble and much more powerful.
Coming Attractions:
I will be showing my progress with videos and and posts as I integrate this new system into the Mall. First up, a complete testbed setup.
-wrtyler-
NeoPixel-based code:
// -------- BLINK --------------
void blinkPixel( uint8_t plugIdentifier, unsigned long delayEffectStart ) {
// Calculate the equivalent NeoPixel triplet the plug is in
uint8_t pixelSetNumber = (plugIdentifier - 1) / 3;
// Calculate the equivalent LED in the NeoPixel triplet the plug
// corresponds to
uint8_t pixelNumber = (plugIdentifier - 1) % 3;
// Get the current brightness of the three pixels in the triplet
uint32_t color = pixels.getPixelColor( pixelSetNumber );
// Get the individual brightness values of the three pixels in the triplet
uint8_t pixel01 = (uint8_t)( (color >> 16) & 0xff ),
pixel02 = (uint8_t)( (color >> 8) & 0xff ),
pixel03 = (uint8_t)( color & 0xff) ;
// Check to see if enough time has elapsed to start the blink effect
if( currentMillis - startMillis >= delayEffectStart ) {
unsigned long period = (onDuration[(plugIdentifier - 1) % section01Pixels]) + (offDuration[(plugIdentifier - 1) % section01Pixels]);
if( pixelNumber == 0 ) {
if( ((millis() % period) >= onDuration[(plugIdentifier - 1) % section01Pixels] ) && (pixel01 == PREFERRED_BRIGHTNESS) ) {
// change the state of pixel
pixel01 = MIN_BRIGHTNESS;
} else if( ((millis() % period) >= offDuration[(plugIdentifier - 1) % section01Pixels] ) && (pixel01 == MIN_BRIGHTNESS) ) {
// change the state of pixel
pixel01 = PREFERRED_BRIGHTNESS;
}
}
if( pixelNumber == 1 ) {
if( ((millis() % period) >= onDuration[(plugIdentifier - 1) % section01Pixels] ) && (pixel02 == PREFERRED_BRIGHTNESS) ) {
// change the state of pixel
pixel02 = MIN_BRIGHTNESS;
} else if( ((millis() % period) >= offDuration[(plugIdentifier - 1) % section01Pixels] ) && (pixel02 == MIN_BRIGHTNESS) ) {
// change the state of pixel
pixel02 = PREFERRED_BRIGHTNESS;
}
}
if( pixelNumber == 2 ) {
if( ((millis() % period) >= onDuration[(plugIdentifier - 1) % section01Pixels] ) && (pixel03 == PREFERRED_BRIGHTNESS) ) {
// change the state of pixelD
pixel03 = MIN_BRIGHTNESS;
} else if( ((millis() % period) >= offDuration[(plugIdentifier - 1) % section01Pixels] ) && (pixel03 == MIN_BRIGHTNESS) ) {
// change the state of pixel
pixel03 = PREFERRED_BRIGHTNESS;
}
}
}
// Update the pixel triplet with the new values
color = pixels.Color( pixel01, pixel02, pixel03 );
pixels.setPixelColor( pixelSetNumber, color );
}
SmartPixel-based code:
// -------- BLINK --------------
void blinkPixel( uint8_t channel, unsigned long delayEffectStart ) {
// Get the current brightness of the channel
uint8_t brightness = NMAAHC.pwmStatus( channel );
// Check to see if enough time has elapsed to start the blink effect
if( currentMillis - startMillis >= delayEffectStart ) {
unsigned long period = (onDuration[channel]) + (offDuration[channel]);
if( ((millis() % period) >= onDuration[channel] ) && (brightness == PREFERRED_BRIGHTNESS) ) {
// change the state of pixel
NMAAHC.pwm( channel, MIN_BRIGHTNESS );
} else if( ((millis() % period) >= offDuration[channel] ) && (brightness == MIN_BRIGHTNESS) ) {
// change the state of pixel
NMAAHC.pwm( channel, PREFERRED_BRIGHTNESS );
}
}
}
1 reply
-
Thanks as always for being a pioneer and also for sharing your work, WRTyler !
