The Maker Pi RP2040 comes with two built-in NeoPixels. Each NeoPixel has a red, green and blue LED inside it. Each of these LEDs can be set to any one of 256 values from 0 (off) to 255 (brightest value).
NeoPixel Setup
12345678
fromneopixelimportNeopixelNUMBER_PIXELS=2STATE_MACHINE=0LED_PIN=18# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGBstrip=Neopixel(NUMBER_PIXELS,STATE_MACHINE,LED_PIN,"GRB")
NeoPixel Blink Lab
In this lab, we will turn the first NeoPixel element on red for 1/2 second and then turn it off for 1/2 second. We repeat this until the program is terminated.
Setting up the NeoPixel Library
We will be calling a NeoPixel driver in the /lib directory. We initiaze our NeoPixel strip by calling the init method all Neopixel() and pass it three parameters:
The number of pixels in the strip (in our case there are just two)
The state machine (in our case 0)
The LED PIN (in our case this is GP18)
1 2 3 4 5 6 7 8 910111213141516171819
fromutimeimportsleep# We are using https://github.com/blaz-r/pi_pico_neopixelfromneopixelimportNeopixelNUMBER_PIXELS=2STATE_MACHINE=0LED_PIN=18# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGBstrip=Neopixel(NUMBER_PIXELS,STATE_MACHINE,LED_PIN,"GRB")whileTrue:# turn on first pixel red for 1/2 secondstrip.set_pixel(0,(255,0,0))strip.show()sleep(.5)strip.set_pixel(0,(0,0,0))# turn all colors offstrip.show()sleep(.5)
importtime# We are using https://github.com/blaz-r/pi_pico_neopixelfromneopixelimportNeopixelNUMBER_PIXELS=2STATE_MACHINE=0LED_PIN=18# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGBstrip=Neopixel(NUMBER_PIXELS,STATE_MACHINE,LED_PIN,"GRB")# Color RGB valuesred=(255,0,0)orange=(255,60,0)# Gamma corrected from G=128 to be less like yellowyellow=(255,150,0)green=(0,255,0)blue=(0,0,255)indigo=(75,0,130)# purple?violet=(138,43,226)# mostly pinkcolor_names=('red','orange','yellow','green','blue','indigo','violet')num_colors=len(color_names)colors=(red,orange,yellow,green,blue,indigo,violet)# set to be 1 to 100 for percent brightnessstrip.brightness(100)color_index=0whileTrue:forcolorincolors:foriinrange(NUMBER_PIXELS):print(i,color_names[color_index])strip.set_pixel(i,color)strip.show()time.sleep(1)color_index+=1ifcolor_index>=num_colors:color_index=0