Skip to content

Commit

Permalink
Update index.md
Browse files Browse the repository at this point in the history
Better approach for final code.
  • Loading branch information
engineershamrock committed Sep 18, 2024
1 parent c056509 commit e233341
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions content/blog/2024/ws2812bled/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,31 +512,35 @@ int main(void)
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.
ws_send_byte( 0b00000000 );
ws_send_byte( 0b00000000 );
ws_send_byte( 0x34 );
if ( led == currPos )
{
// Send a blue colour at the correct position.
ws_send_byte( 0b00000000 );
ws_send_byte( 0b00000000 );
ws_send_byte( 0x34 );
}
else
{
// Reset the LED when not at the correct position.
ws_send_byte( 0b00000000 );
ws_send_byte( 0b00000000 );
ws_send_byte( 0b00000000 );
}
}
else
{
// Reset the LED when not at the correct position.
ws_send_byte( 0b00000000 );
ws_send_byte( 0b00000000 );
ws_send_byte( 0b00000000 );
}
}
liPos++;
currPos = ((liPos + ledCount) % (ledCount*2)) - ledCount ;
liPos++;
currPos = ((liPos + ledCount) % (ledCount*2)) - ledCount ;
// Invert the position to track back and forth.
if ( currPos < 0 )
currPos = currPos * -1;
// Invert the position to track back and forth.
if ( currPos < 0 )
currPos = currPos * -1;
__delay_us(100);
__delay_us(100);
}
}
}
```
Expand Down

0 comments on commit e233341

Please sign in to comment.