Update index.md

Better approach for final code.
This commit is contained in:
engineershamrock
2024-09-18 20:38:35 +01:00
parent c0565091c0
commit e2333416ec

View File

@@ -512,31 +512,35 @@ int main(void)
while (1) while (1)
{ {
for ( int led = 0 ; led < ledCount ; led ++ ) liPos = 0;
for ( int t = 0 ; t < ledCount*2; t++)
{ {
if ( led == currPos ) for ( int led = 0 ; led < ledCount ; led ++ )
{ {
// Send a blue colour at the correct position. if ( led == currPos )
ws_send_byte( 0b00000000 ); {
ws_send_byte( 0b00000000 ); // Send a blue colour at the correct position.
ws_send_byte( 0x34 ); ws_send_byte( 0b00000000 );
} ws_send_byte( 0b00000000 );
else ws_send_byte( 0x34 );
{ }
// Reset the LED when not at the correct position. else
ws_send_byte( 0b00000000 ); {
ws_send_byte( 0b00000000 ); // Reset the LED when not at the correct position.
ws_send_byte( 0b00000000 ); ws_send_byte( 0b00000000 );
ws_send_byte( 0b00000000 );
ws_send_byte( 0b00000000 );
}
} }
liPos++;
currPos = ((liPos + ledCount) % (ledCount*2)) - ledCount ;
// Invert the position to track back and forth.
if ( currPos < 0 )
currPos = currPos * -1;
__delay_us(100);
} }
liPos++;
currPos = ((liPos + ledCount) % (ledCount*2)) - ledCount ;
// Invert the position to track back and forth.
if ( currPos < 0 )
currPos = currPos * -1;
__delay_us(100);
} }
} }
``` ```