start:micro-bit:neopixel
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| start:micro-bit:neopixel [2019/05/15 12:39] – [Programmation] gerardadmin | start:micro-bit:neopixel [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ======= | ||
| + | | ||
| + | |||
| + | --------- | ||
| + | |||
| + | |||
| + | |||
| + | **Transformez votre Micro:bit en horloge, chronomètre, | ||
| + | |||
| + | Le Zip Halo est l' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | ==== Programmation ==== | ||
| + | [[http:// | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | |||
| + | === En micropython === | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | <file python exemple_neopixel_micropython.py> | ||
| + | |||
| + | |||
| + | """ | ||
| + | neopixel_random.py | ||
| + | |||
| + | Repeatedly displays random colours onto the LED strip. | ||
| + | This example requires a strip of 8 Neopixels (WS2812) connected to pin0. | ||
| + | |||
| + | """ | ||
| + | from microbit import * | ||
| + | import neopixel | ||
| + | from random import randint | ||
| + | |||
| + | # Setup the Neopixel strip on pin0 with a length of 8 pixels | ||
| + | np = neopixel.NeoPixel(pin0, | ||
| + | |||
| + | while True: | ||
| + | #Iterate over each LED in the strip | ||
| + | |||
| + | for pixel_id in range(0, len(np)): | ||
| + | red = randint(0, 60) | ||
| + | green = randint(0, 60) | ||
| + | blue = randint(0, 60) | ||
| + | |||
| + | # Assign the current LED a random red, green and blue value between 0 and 60 | ||
| + | np[pixel_id] = (red, green, blue) | ||
| + | |||
| + | # Display the current pixel data on the Neopixel strip | ||
| + | np.show() | ||
| + | sleep(100) | ||
| + | | ||
| + | </ | ||
| + | |||
| + | |||
| + | === En javascript === | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | <code javascript exemple_neopixel001.js> | ||
| + | |||
| + | let ring: neopixel.Strip = null | ||
| + | ring = neopixel.create(DigitalPin.P2, | ||
| + | basic.forever(function () { | ||
| + | for (let index = 0; index <= 23; index++) { | ||
| + | ring.setPixelColor(index, | ||
| + | ring.show() | ||
| + | basic.pause(50) | ||
| + | ring.setPixelColor(index, | ||
| + | ring.show() | ||
| + | } | ||
| + | }) | ||
| + | |||
| + | </ | ||
