IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

Circuit Python Adafruit Circuit Playground Bluefruit


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Novembre 2019
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 85
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Novembre 2019
    Messages : 2
    Par défaut Circuit Python Adafruit Circuit Playground Bluefruit
    bonjour
    je recherche un specialiste ou une personne vraiment doué en language circuitpython
    avec le logiciel MU
    j utilise circuit python avec la carte adafruit circuit playground blufruit
    y a t il une personne qui voudrait m aider a ecrire un code pour allumer des leds reactive au son.
    je suis deja sur un forum adafruit mais c est compliqué je parle pas bien anglais
    merci pour vos reponses
    y a t il une personne experimenté ici qui connait le logiciel Mu, circuit python et
    qui pourrait m aider avec circuit playground blufruit pour faire un code?

  2. #2
    Membre éclairé Avatar de nekcorp
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2006
    Messages
    592
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Décembre 2006
    Messages : 592
    Par défaut
    Bonjour,

    alors effectivement si tu ne parles pas bien anglais c'est toujours plus compliqué.

    Le fait de ne pas bien parlé anglais ne t'empêche pas de fournir un bout de code pour que l'on voit que tu as cherché à faire quelque chose, sans quoi les gens passeront devant ton problème sans y prêter attention.

  3. #3
    Nouveau candidat au Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Novembre 2019
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 85
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Novembre 2019
    Messages : 2
    Par défaut merci
    merci pour la reponse

    voici le code programme qui fonctionne avec une app bluefruit sur apple

    j aimerais avoir aussi les leds interne a la carte qui seraient en reaction avec le son avec la carte circuit playground bluefruit
    ce code ci dessous ne fonctionne qu avec 10 led externe, alors que je voudrais connecter un badeau led de 200 led au moins
    et pouvoir augmenter la sensibiliter du micro au maximum



    https://learn.adafruit.com/no-solder...ooth-disco-tie
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
     
     
    """
    LED Disco Tie with Bluetooth
    =========================================================
    Give your suit an sound-reactive upgrade with Circuit
    Playground Bluefruit & Neopixels. Set color and animation
    mode using the Bluefruit LE Connect app.
     
    Author: Collin Cunningham for Adafruit Industries, 2019
    """
    # pylint: disable=global-statement
     
    import time
    import array
    import math
    import audiobusio
    import board
    import neopixel
    from adafruit_ble.uart_server import UARTServer
    from adafruit_bluefruit_connect.packet import Packet
    from adafruit_bluefruit_connect.color_packet import ColorPacket
    from adafruit_bluefruit_connect.button_packet import ButtonPacket
     
    uart_server = UARTServer()
     
    # User input vars
    mode = 0 # 0=audio, 1=rainbow, 2=larsen_scanner, 3=solid
    user_color= (127,0,0)
     
    # Audio meter vars
    PEAK_COLOR = (100, 0, 255)
    NUM_PIXELS = 10
    CURVE = 2
    SCALE_EXPONENT = math.pow(10, CURVE * -0.1)
    NUM_SAMPLES = 160
     
    # Restrict value to be between floor and ceiling.
    def constrain(value, floor, ceiling):
        return max(floor, min(value, ceiling))
     
    # Scale input_value between output_min and output_max, exponentially.
    def log_scale(input_value, input_min, input_max, output_min, output_max):
        normalized_input_value = (input_value - input_min) / \
                                 (input_max - input_min)
        return output_min + \
            math.pow(normalized_input_value, SCALE_EXPONENT) \
            * (output_max - output_min)
     
    # Remove DC bias before computing RMS.
    def normalized_rms(values):
        minbuf = int(mean(values))
        samples_sum = sum(
            float(sample - minbuf) * (sample - minbuf)
            for sample in values
        )
     
        return math.sqrt(samples_sum / len(values))
     
    def mean(values):
        return sum(values) / len(values)
     
    def volume_color(volume):
        return 200, volume * (255 // NUM_PIXELS), 0
     
    # Set up NeoPixels and turn them all off.
    pixels = neopixel.NeoPixel(board.A1, NUM_PIXELS, brightness=0.1, auto_write=False)
    pixels.fill(0)
    pixels.show()
     
    mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
                           sample_rate=16000, bit_depth=16)
     
    # Record an initial sample to calibrate. Assume it's quiet when we start.
    samples = array.array('H', [0] * NUM_SAMPLES)
    mic.record(samples, len(samples))
    # Set lowest level to expect, plus a little.
    input_floor = normalized_rms(samples) + 10
    # Corresponds to sensitivity: lower means more pixels light up with lower sound
    input_ceiling = input_floor + 500
    peak = 0
     
    def wheel(wheel_pos):
        # Input a value 0 to 255 to get a color value.
        # The colours are a transition r - g - b - back to r.
        if wheel_pos < 0 or wheel_pos > 255:
            r = g = b = 0
        elif wheel_pos < 85:
            r = int(wheel_pos * 3)
            g = int(255 - wheel_pos*3)
            b = 0
        elif wheel_pos < 170:
            wheel_pos -= 85
            r = int(255 - wheel_pos*3)
            g = 0
            b = int(wheel_pos*3)
        else:
            wheel_pos -= 170
            r = 0
            g = int(wheel_pos*3)
            b = int(255 - wheel_pos*3)
        return (r, g, b)
     
    def rainbow_cycle(delay):
        for j in range(255):
            for i in range(NUM_PIXELS):
                pixel_index = (i * 256 // NUM_PIXELS) + j
                pixels[i] = wheel(pixel_index & 255)
            pixels.show()
            time.sleep(delay)
     
    def audio_meter(new_peak):
        mic.record(samples, len(samples))
        magnitude = normalized_rms(samples)
     
        # Compute scaled logarithmic reading in the range 0 to NUM_PIXELS
        c = log_scale(constrain(magnitude, input_floor, input_ceiling),
                      input_floor, input_ceiling, 0, NUM_PIXELS)
     
        # Light up pixels that are below the scaled and interpolated magnitude.
        pixels.fill(0)
        for i in range(NUM_PIXELS):
            if i < c:
                pixels[i] = volume_color(i)
            # Light up the peak pixel and animate it slowly dropping.
            if c >= new_peak:
                new_peak = min(c, NUM_PIXELS - 1)
            elif new_peak > 0:
                new_peak = new_peak - 1
            if new_peak > 0:
                pixels[int(new_peak)] = PEAK_COLOR
        pixels.show()
        return new_peak
     
    pos = 0  # position
    direction = 1  # direction of "eye"
     
    def larsen_set(index, color):
        if index < 0:
            return
        else:
            pixels[index] = color
     
    def larsen(delay):
        global pos
        global direction
        color_dark = (int(user_color[0]/8), int(user_color[1]/8),
                      int(user_color[2]/8))
        color_med = (int(user_color[0]/2), int(user_color[1]/2),
                     int(user_color[2]/2))
     
        larsen_set(pos - 2, color_dark)
        larsen_set(pos - 1, color_med)
        larsen_set(pos, user_color)
        larsen_set(pos + 1, color_med)
     
        if (pos + 2) < NUM_PIXELS:
            # Dark red, do not exceed number of pixels
            larsen_set(pos + 2, color_dark)
     
        pixels.write()
        time.sleep(delay)
     
        # Erase all and draw a new one next time
        for j in range(-2, 2):
            larsen_set(pos + j, (0, 0, 0))
            if (pos + 2) < NUM_PIXELS:
                larsen_set(pos + 2, (0, 0, 0))
     
        # Bounce off ends of strip
        pos += direction
        if pos < 0:
            pos = 1
            direction = -direction
        elif pos >= (NUM_PIXELS - 1):
            pos = NUM_PIXELS - 2
            direction = -direction
     
    def solid(new_color):
        pixels.fill(new_color)
        pixels.show()
     
    def map_value(value, in_min, in_max, out_min, out_max):
        out_range = out_max - out_min
        in_range = in_max - in_min
        return out_min + out_range * ((value - in_min) / in_range)
     
    speed = 6.0
    wait = 0.097
     
    def change_speed(mod, old_speed):
        new_speed = constrain(old_speed + mod, 1.0, 10.0)
        return(new_speed, map_value(new_speed, 10.0, 0.0, 0.01, 0.3))
     
    while True:
        # While BLE is *not* connected
        if not uart_server.connected:
            # OK to call again even if already advertising
            uart_server.start_advertising()
     
        # While BLE is connected
        else:
            if uart_server.in_waiting:
                packet = Packet.from_stream(uart_server)
     
                # Received ColorPacket
                if isinstance(packet, ColorPacket):
                    user_color = packet.color
     
                # Received ButtonPacket
                elif isinstance(packet, ButtonPacket):
                    if packet.pressed:
                        if packet.button == ButtonPacket.UP:
                            speed, wait = change_speed(1, speed)
                        elif packet.button == ButtonPacket.DOWN:
                            speed, wait = change_speed(-1, speed)
                        elif packet.button == ButtonPacket.BUTTON_1:
                            mode = 0
                        elif packet.button == ButtonPacket.BUTTON_2:
                            mode = 1
                        elif packet.button == ButtonPacket.BUTTON_3:
                            mode = 2
                        elif packet.button == ButtonPacket.BUTTON_4:
                            mode = 3
     
        # Determine animation based on mode
        if mode == 0:
            peak = audio_meter(peak)
        elif mode == 1:
            rainbow_cycle(0.001)
        elif mode == 2:
            larsen(wait)
        elif mode == 3:
            solid(user_color)
    voila en fait il faudrait par miracle arriver a inclure dans ce code un autre code pour que les leds externe soit au nombre de 200 voir plus si possible
    et surtout que la carte circuit playground bluefruit ou il y a dessus 10 led puisse aussi reagir avec le son
    exemple de code pour la carte interne du circuit playground bluefruit
    https://core-electronics.com.au/tuto...-tutorial.html
    voici le code qui fait marcher a merveille les 10 led sur la carte circuit playground express qui marche avec ma carte bluefruit
    mais il manque le code pour les leds externe celui donner plus haut
    voici le code de la video 10 led interne

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    import arrayimport array
    import mathimport math
     
    import audiobusioimport audiobusio
    import boardimport board
    import neopixelimport neopixel
     
    # Exponential scaling factor.# Exponential scaling factor.
    # Should probably be in range -10 .. 10 to be reasonable.# Should probably be in range -10 .. 10 to be reasonable.
    CURVE = 2= 2
    SCALE_EXPONENT = math.pow(10, CURVE * -0.1)= math.pow(10, CURVE * -0.1)
     
    PEAK_COLOR = (100, 0, 255)= (100, 0, 255)
    NUM_PIXELS = 10= 10
     
    # Number of samples to read at once.# Number of samples to read at once.
    NUM_SAMPLES = 160= 160
     
     
    # Restrict value to be between floor and ceiling.# Restrict value to be between floor and ceiling.
     
     
    def constrain(value, floor, ceiling):def constrain(value, floor, ceiling):
        return max(floor, min(value, ceiling))return max(floor, min(value, ceiling))
     
     
    # Scale input_value between output_min and output_max, exponentially.# Scale input_value between output_min and output_max, exponentially.
     
     
    def log_scale(input_value, input_min, input_max, output_min, output_max):def log_scale(input_value, input_min, input_max, output_min, output_max):
        normalized_input_value = (input_value - input_min) / \= (input_value - input_min) / \
                                 (input_max - input_min)(input_max - input_min)
        return output_min + \return output_min + \
            math.pow(normalized_input_value, SCALE_EXPONENT) \.pow(normalized_input_value, SCALE_EXPONENT) \
            * (output_max - output_min)* (output_max - output_min)
     
     
    # Remove DC bias before computing RMS.# Remove DC bias before computing RMS.
     
     
    def normalized_rms(values):def normalized_rms(values):
        minbuf = int(mean(values))= int(mean(values))
        samples_sum = sum(= sum(
            float(sample - minbuf) * (sample - minbuf)float(sample - minbuf) * (sample - minbuf)
            for sample in valuesfor sample in values
        ))
     
        return math.sqrt(samples_sum / len(values))return math.sqrt(samples_sum / len(values))
     
     
    def mean(values):def mean(values):
        return sum(values) / len(values)return sum(values) / len(values)
     
     
    def volume_color(volume):def volume_color(volume):
        return 200, volume * (255 // NUM_PIXELS), 0return 200, volume * (255 // NUM_PIXELS), 0
     
     
    # Main program# Main program
     
     
    # Set up NeoPixels and turn them all off.# Set up NeoPixels and turn them all off.
    pixels = neopixel.NeoPixel(board.NEOPIXEL, NUM_PIXELS,= neopixel.NeoPixel(board.NEOPIXEL, NUM_PIXELS,
                               brightness=0.1, auto_write=False)=0.1, auto_write=False)
    pixels.fill(0).fill(0)
    pixels.show().show()
     
    """ """ 
    # For CircuitPython 2.x:
    mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
                           frequency=16000, bit_depth=16)
    # For Circuitpython 3.0 and up, "frequency" is now called "sample_rate".frequency" is now called "sample_rate".
    # Comment the lines above and uncomment the lines below.
    """
    mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,= audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
                           sample_rate=16000, bit_depth=16)=16000, bit_depth=16)
     
    # Record an initial sample to calibrate. Assume it's quiet when we start.# Record an initial sample to calibrate. Assume it's quiet when we start.
    samples = array.array('H', [0] * NUM_SAMPLES)= array.array('H', [0] * NUM_SAMPLES)
    mic.record(samples, len(samples)).record(samples, len(samples))
    # Set lowest level to expect, plus a little.# Set lowest level to expect, plus a little.
    input_floor = normalized_rms(samples) + 10= normalized_rms(samples) + 10
    # OR: used a fixed floor# OR: used a fixed floor
    # input_floor = 50# input_floor = 50
     
    # You might want to print the input_floor to help adjust other values.# You might want to print the input_floor to help adjust other values.
    # print(input_floor)# print(input_floor)
     
    # Corresponds to sensitivity: lower means more pixels light up with lower sound# Corresponds to sensitivity: lower means more pixels light up with lower sound
    # Adjust this as you see fit.# Adjust this as you see fit.
    input_ceiling = input_floor + 500= input_floor + 500
     
    peak = 0= 0
    while True:while True:
        mic.record(samples, len(samples)).record(samples, len(samples))
        magnitude = normalized_rms(samples)= normalized_rms(samples)
        # You might want to print this to see the values.# You might want to print this to see the values.
        # print(magnitude)# print(magnitude)
     
        # Compute scaled logarithmic reading in the range 0 to NUM_PIXELS# Compute scaled logarithmic reading in the range 0 to NUM_PIXELS
        c = log_scale(constrain(magnitude, input_floor, input_ceiling),= log_scale(constrain(magnitude, input_floor, input_ceiling),
                      input_floor, input_ceiling, 0, NUM_PIXELS), input_ceiling, 0, NUM_PIXELS)
     
        # Light up pixels that are below the scaled and interpolated magnitude.# Light up pixels that are below the scaled and interpolated magnitude.
        pixels.fill(0).fill(0)
        for i in range(NUM_PIXELS):for i in range(NUM_PIXELS):
            if i < c:if i < c:
                pixels[i] = volume_color(i)[i] = volume_color(i)
            # Light up the peak pixel and animate it slowly dropping.# Light up the peak pixel and animate it slowly dropping.
            if c >= peak:if c >= peak:
                peak = min(c, NUM_PIXELS - 1)= min(c, NUM_PIXELS - 1)
            elif peak > 0:elif peak > 0:
                peak = peak - 1= peak - 1
            if peak > 0:if peak > 0:
                pixels[int(peak)] = PEAK_COLOR[int(peak)] = PEAK_COLOR
        pixels.show().show()

Discussions similaires

  1. [PageControl] Raccourcis claviers court-circuités
    Par Manopower dans le forum Composants VCL
    Réponses: 8
    Dernier message: 04/09/2009, 16h52
  2. problème d'algorithme pour trouver les circuit d'un graphe
    Par marc_dd dans le forum Algorithmes et structures de données
    Réponses: 11
    Dernier message: 21/08/2006, 16h36
  3. Media circuit de voiture
    Par japle dans le forum Développement 2D, 3D et Jeux
    Réponses: 2
    Dernier message: 19/07/2006, 21h06
  4. [Circuits] Truth Table - Circuits gates
    Par virtuadrack dans le forum Ordinateurs
    Réponses: 5
    Dernier message: 26/10/2005, 19h42
  5. Réponses: 4
    Dernier message: 16/03/2004, 18h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo