Checkerboard

With CodeBug it is really easy to create a checkerboard pattern like on a chessboard. You could turn each LED on individually but this would need a lot of typing. Instead there’s an easier way to set the leds in an entire row at once, using the set_row command.

Start up a Python shell in a command terminal:

python3

Import and initialise the CodeBug tether module:

import codebug_tether

c = codebug_tether.CodeBug()

Now set the rows:

c.set_row(0,0b10101)

c.set_row(1,0b01010)

c.set_row(2,0b10101)

c.set_row(3,0b01010)

c.set_row(4,0b10101)

Does the pattern looks like how you imagined it would? Try changing one of the rows giving it a different value and see how the pattern changes, e.g.

c.set_row(2,0b11100)

This is a good way to visualise this pattern

The 0b at the start of the value simply let’s you know that this is a binary number.


Activities with this step

Back to top