Lesson 1: Lighting Lights

The basics of controlling the LED strip. Loops and Lists.
Note:
  • In the code examples, you may need to change the board pin ( board.GP0 ) based on your specific pico setup.

References:

  1. QuickRef: Lists

Turning on a light

Examine the test1.py file:


            import board
            import neopixel

            pixels = neopixel.NeoPixel(board.GP0, 20)

            pixels[2] = (10,0,0)
            
Looking through the code line by line:

Lines 1 and 2:


                import board
                import neopixel
              
Import two modules that we need to light the LED's.

Line 4:


              pixels = neopixel.NeoPixel(board.GP0, 20)
              
This activates the LED strip. Specifically it indicates that:

Line 6:


              pixels[2] = (10,0,0)
              
This makes the third light red.

Assignment 1

Light up the 5th light.
Code ▼

Assignment 2

Make the second light green.
Code ▼

Assignment 3

Make the fourth light yellow.
Notes ▼
Code ▼

Reverse Indexing (in python)

Make the last light blue (using reverse indexing in python).

With 20 pixels you can light up the last one using reverse indexing:


              pixels[-1] = (0,0,100)
            

which gives the same result as:


              pixels[19] = (0,0,100)
            

This is quite useful, because to do the second to last pixel, you'd use:


              pixels[-2] = (0,0,100)
            

So the full code to turn the last light blue would be:


            import board
            import neopixel

            pixels = neopixel.NeoPixel(board.GP0, 20)

            pixels[-1] = (0,0,100)
            

Assignment 5

Make the last three lights red, blue, and green respectively.
Code ▼

Mixing Colors

Each LED Pixel really has three small LED's inside: one each of red, blue, and green.

To create different colors you'll just need to mix different levels of red, blue, and green. These are refered to as rgb values because the intensity of each color is given in that order. So, to make yellow you'll need to mix red and green:


              pixels[0] = (20,20,0)
            

And if you look carefully, you might be able to see the red and green led's are lit in the pixel.

Mix the three colors equally to get white, and no color at all (0,0,0) gives black.

If you do an internet search for "color picker" you should get something that gives you rgb values for different colors.

Assignment 6

Make the second light pink.
Code ▼

Assignment 7

Make the third light white.