Skip to content

The micro:bit Talking LED Blink And Breath is a micro:bit Electronic Educational Engagement Tool designed to help students create a talking blink and breath application.

License

Notifications You must be signed in to change notification settings

mytechnotalent/MicroPython-micro-bit-Talking-Blink-And-Breath

Repository files navigation

image

MicroPython-micro-bit

Talking Blink And Breath

The micro:bit Talking LED Blink And Breath is a micro:bit Electronic Educational Engagement Tool designed to help students create a talking blink and breath application.

Schematic

image
*** NOTE *** USE PIN1 INSTEAD OF PIN0 (GREEN WIRE)

Parts

micro:bit
Ks0360 Keyestudio Sensor Shield V2 for BBC micro:bit

  • Keyestudio Micro bit Sensor V2 Shield * 1
  • keyestudio 3W LED Module * 1
  • Dupont jumper wire * 3

STEP 1: Navigate To The FREE micro:bit Python Web Editor

micro:bit Python Web Editor

image

STEP 2: Plug micro:bit V2 Into Computer

*PLUG IN USB CABLE TO COMPUTER AND DEVICE

STEP 3: Click CONNECT

image

STEP 4: Click "BBC micro:bit CMSIS-DAP" & CONNECT

image

STEP 5: Highlight Sample Code - Select All

image

STEP 6: Click Backspace On Keyboard To Delete Sample Code

image

STEP 7: Copy Study Buddy Python Code Template Into Python Web Editor

CODE

from time import sleep
from time import sleep_ms

from microbit import pin1, display, Image
from speech import say

SPEED = 95

while True:
    # We set the blink_count to 0 and increment
    # 2 times to allow this while loop to execute
    # twice
    blink_count = 0
    while blink_count < 2:
        pin1.write_digital(1)
        display.show(Image.SURPRISED)
        say('The light is on!', speed=SPEED)  
        display.show(Image.HAPPY)
        sleep(5)
        
        pin1.write_digital(0)
        display.show(Image.SURPRISED)
        say('The light is off!', speed=SPEED)
        display.show(Image.HAPPY)
        sleep(5)
        
        blink_count  = 1
        
    # We set the breath_count to 0 and increment
    # 2 times to allow this while loop to execute
    # twice
    breath_count = 0    
    val = 0
    while breath_count < 2:
        display.show(Image.SURPRISED)
        say('The light is getting brighter!', speed=SPEED)
        display.show(Image.HAPPY)
        
        # The val is initialized to 0 on line 6 and 
        # increments by one through each iteration
        # through the while loop until it hits 
        # 1022 and as it does it increments the value
        # of pin1 which makes the light brigter
        # every 5 ms
        while val <= 1022:
            val  = 1
            pin1.write_analog(val)
            sleep_ms(5)
            
        display.show(Image.SURPRISED)
        say('The light is getting darker!', speed=SPEED)
        display.show(Image.HAPPY)    
        
        # After we complete the first loop the val
        # is now equal to 1023 so during this
        # while loop it gets smaller until it hits 
        # 0 and as it decrements the value
        # of pin1 which makes the light darker
        # every 5 ms
        while val > 0:
            val -= 1
            pin1.write_analog(val)
            sleep_ms(5)  
            
        breath_count  = 1

STEP 8: Rename Script Name To talking_blink_and_breath

STEP 9: Click Save

image

STEP 10: Click Download Python Script

image

STEP 11: Click Flash

image

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Apache License, Version 2.0

Releases

No releases published

Packages

No packages published

Languages