Micro:bit and NEOPIXEL ring make:code examples

In this example we decided to play about with a Neopixel ring again but this time all of the examples are created using the Microsoft Make:code editor – https://makecode.microbit.org

Neopixel are basically Ws2812B – here is a reminder of what these are

WS2812B is a intelligent control LED light source that the c ontrol circuit and RGB chip are integrated in a package of 5050 components. It internal include intelligent digital port data latch and signal reshaping ampli fication drive circuit. Also include a precision internal oscillator and a 12V voltage programmable constant curr e – nt control part, e ffectively ensuring the pixel point light color height consistent . The data transfer protocol use single NZR communication mode.

After the pixel power-on reset, the DIN port receive data from controller, the first pixel collect initial 24bit data then sent to the internal data latch, the other data which reshaping by the internal signal reshaping amplification circuit sent to the next cascade pixel through the DO port.

After transmission for each pixel , the signal to reduce 24bit. pixel adopt auto resha – ping transmit technology, making the pixel cascade number is not limited the signal transmission, only depend on the speed of signal transmission. LED with low driving voltage, environmental protection and energy saving, high brightness, scattering angl e is large, good consistency, low power, long life and other advantages. The control chip integrated in LED above becoming more simple circuit, small volume, convenient installation

Parts List

These are the parts that I used, the expansion board is optional but I prefer using this to crocodile clips

Part Link
Microbit Micro:bit Development Board,
Microbit expansion board (optional) Edge Breakout I/O Expansion Extension Board for BBC micro:bit
16 LED NEOPIXEL ring 1 8 12 16 24 32 40 48 60 93 241 Bits LEDs WS2812B SK6812 5050 RGB LED Ring

Layout

Easy to connect I used 0 for DIN

Code Examples

Here are the JavaScript code examples which can be copied into the editor

Example 1

[codesyntax lang=”javascript”]

let strip: neopixel.Strip = null
strip = neopixel.create(DigitalPin.P0, 16, NeoPixelMode.RGB_RGB)
basic.forever(function () {
    for (let index = 0; index <= 15; index++) {
        strip.setBrightness(10)
        strip.setPixelColor(index, neopixel.colors(NeoPixelColors.Blue))
        strip.show()
    }
})

[/codesyntax]

Example 2

[codesyntax lang=”javascript”]

let strip: neopixel.Strip = null
strip = neopixel.create(DigitalPin.P0, 16, NeoPixelMode.RGB_RGB)
basic.forever(function () {
    for (let index = 0; index <= 15; index++) {
        strip.setBrightness(10)
        strip.setPixelColor(index, neopixel.colors(NeoPixelColors.Red))
        strip.show()
        basic.pause(1000)
        strip.setPixelColor(index, neopixel.colors(NeoPixelColors.Green))
        strip.show()
        basic.pause(1000)
        strip.setPixelColor(index, neopixel.colors(NeoPixelColors.Blue))
        strip.show()
        basic.pause(1000)
    }
})

[/codesyntax]

Example 3

[codesyntax lang=”cpp”]

let strip: neopixel.Strip = null
let index = 0
strip = neopixel.create(DigitalPin.P0, 16, NeoPixelMode.RGB_RGB)
basic.forever(function () {
    for (let index = 0; index <= 15; index++) {
        strip.setBrightness(10)
        strip.setPixelColor(index, neopixel.colors(NeoPixelColors.Red))
        strip.show()
    }
    basic.pause(1000)
    for (let index = 0; index <= 15; index++) {
        strip.setPixelColor(index, neopixel.colors(NeoPixelColors.Green))
        strip.show()
    }
    basic.pause(1000)
    for (let index = 0; index <= 15; index++) {
        strip.setPixelColor(index, neopixel.colors(NeoPixelColors.Blue))
        strip.show()
    }
    basic.pause(1000)
})

[/codesyntax]

Example 4

[codesyntax lang=”javascript”]

let strip: neopixel.Strip = null
strip = neopixel.create(DigitalPin.P0, 16, NeoPixelMode.RGB_RGB)
basic.forever(function () {
    for (let index = 0; index <= 15; index++) {
        strip.setBrightness(10)
        strip.setPixelColor(index, neopixel.rgb(Math.randomRange(0, 254), Math.randomRange(0, 254), Math.randomRange(0, 254)))
        strip.show()
    }
    basic.pause(100)
})

[/codesyntax]

 

Embedded Example

The project is available, here is a look at the simulator for the last code example

 

Leave a Comment

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views :