
"""


Auteur: anonyme

Interface: microbit

Nom du projet: Visualiser un niveau sonore

Description: No-description

Toolbox: vittascience

Mode: blocks

Blocks: <xml xmlns="https://developers.google.com/blockly/xml"><block type="forever" id="o[WN]+eeF.OUxGch67@8" x="262" y="-63"><statement name="DO"><block type="display_defineNeopixel" id="%?{YQ.x47Cii@lJ?Stzk"><field name="N">30</field><field name="PIN">pin0</field><next><block type="controls_if" id="kGc9j~{wu^d_kJRF-7Nz"><mutation else="1"></mutation><value name="IF0"><block type="logic_compare" id="$M2=4xBHlwK[NbTRB(Q8"><field name="OP">LT</field><value name="A"><block type="io_micro_getSoundLevel" id="ohd)cXhP{X_O4fMiLs{D"></block></value><value name="B"><shadow type="math_number" id="O!rMzH$V|hm%ACK/y(Gm"><field name="NUM">40</field></shadow></value></block></value><statement name="DO0"><block type="display_neopixel_controlAllLedPalette" id="7lWPJ91,|4O-1DHJxJ=1"><field name="PIN">pin0</field><value name="COLOR"><block type="colour_picker" id="z.OVCZJXqyb?cIx(aix5"><field name="COLOUR">#33cc00</field></block></value></block></statement><statement name="ELSE"><block type="controls_if" id="zf0uQFKnhA$WSam:n/by"><mutation else="1"></mutation><value name="IF0"><block type="logic_operation" id="TTYbzMmar[}RB@9$shP["><field name="OP">AND</field><value name="A"><block type="logic_compare" id="kcga(d:KYB=0@{{hr2[5"><field name="OP">GT</field><value name="A"><block type="io_micro_getSoundLevel" id="M6mK5W|6$t_%tM@-=[{c"></block></value><value name="B"><shadow type="math_number" id="O(J|oi0y[Q)$@3ZuI5@_"><field name="NUM">40</field></shadow></value></block></value><value name="B"><block type="logic_compare" id="FA6J*n8N^rbO[1I|y:yE"><field name="OP">LT</field><value name="A"><block type="io_micro_getSoundLevel" id="XH/xZEkwOd)v.R~IqR,e"></block></value><value name="B"><shadow type="math_number" id="i=qhhwDVz0Q+FfCZ9no@"><field name="NUM">80</field></shadow></value></block></value></block></value><statement name="DO0"><block type="display_neopixel_controlAllLedPalette" id="hB-SsP6!^.H.mo%;s^b~"><field name="PIN">pin0</field><value name="COLOR"><block type="colour_picker" id=".1t+AocdOJ[8N2O_p[`Y"><field name="COLOUR">#ffff00</field></block></value></block></statement><statement name="ELSE"><block type="controls_if" id="?0PSmF]%c/?fBh.II8]H"><value name="IF0"><block type="logic_operation" id="VvcOm3f-(Rx`/o}n(YgI"><field name="OP">AND</field><value name="A"><block type="logic_compare" id="Z?AHoVpOyTV6-+4n+iNE"><field name="OP">GT</field><value name="A"><block type="io_micro_getSoundLevel" id="tx)W_Pp~N}jRkoeFrh?7"></block></value><value name="B"><shadow type="math_number" id="!J1x|+=SH*zb_h*Ugd_9"><field name="NUM">80</field></shadow></value></block></value><value name="B"><block type="logic_compare" id="UZNHtekgB@hYRD0)zW9%"><field name="OP">LT</field><value name="A"><block type="io_micro_getSoundLevel" id="]x=uYyfu$P?|YX:,*9nm"></block></value><value name="B"><shadow type="math_number" id="$[x/OvE{6+FtTFpnP/sb"><field name="NUM">128</field></shadow></value></block></value></block></value><statement name="DO0"><block type="display_neopixel_controlAllLedPalette" id="TbtF_1L;0{DyJAX}L_[["><field name="PIN">pin0</field><value name="COLOR"><block type="colour_picker" id="Z{Xl9#lWNfSm~iG4KyFM"><field name="COLOUR">#ff0000</field></block></value></block></statement></block></statement></block></statement></block></next></block></statement></block><block type="on_start" id="G[=T#8yqB70`NFgYq}GP" deletable="false" x="-137" y="12"></block></xml>

Projet généré par Vittascience.

Ce fichier contient le code textuel ainsi que le code blocs. Il peut être importé de nouveau

sur l'interface http://vittascience.com/microbit


"""

from microbit import *
import neopixel

NP_LED_COUNT_0 = 30

# Neopixel on pin0
np_0 = neopixel.NeoPixel(pin0, NP_LED_COUNT_0)

def neopixel_showAllLed(neoPx, ledCount, R, G, B):
  for i in range(ledCount):
    neoPx[i] = (R, G, B)
  neoPx.show()

while True:
  if microphone.sound_level() < 40:
    neopixel_showAllLed(np_0, NP_LED_COUNT_0, 51, 204, 0)
  else:
    if microphone.sound_level() > 40 and microphone.sound_level() < 80:
      neopixel_showAllLed(np_0, NP_LED_COUNT_0, 255, 255, 0)
    else:
      if microphone.sound_level() > 80 and microphone.sound_level() < 128:
        neopixel_showAllLed(np_0, NP_LED_COUNT_0, 255, 0, 0)
