Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
BhavithiranSC Lim
Published © MIT

EDU:BIT Music Turntable | MicroPython

Guide to program Music Turntable with EDU:BIT (project kit for micro:bit) using MicroPython

BeginnerFull instructions provided30 minutes541
EDU:BIT Music Turntable | MicroPython

Things used in this project

Hardware components

EDU:BIT
Cytron Technologies EDU:BIT
×1

Software apps and online services

Mu
Python Editor for micro:bit

Story

Read more

Code

Music Turntable

Python
This tutorial's full code
from edubit import *
import music

time = 0
start = 0
mode = 0
state = False

while True:
    init()                                     # initialize EDU:BIT
    if button_b.is_pressed():                  # button B pressed
        run_motor(M1,Forward,20)               # run dc motor
        sleep(3000)
        mode = 1
    elif button_a.is_pressed():                # button A pressed
        music.stop()                           # stop the music
        brake_motor(M1)                        # stop the motor
        mode = 0
        
    if is_IR_sensor_triggered() == True and is_IR_sensor_triggered() != state:    # if ir sensor triggered
        start = running_time()                # capture running time
        state = True
    elif is_IR_sensor_triggered() == False and is_IR_sensor_triggered() != state: # if ir sensor is not triggered
        end = running_time()                  # capture running time
        time = end - start                    
        state = False  
        
    if mode == 1:
        if time > 170:
            music.play(music.NYAN,wait=False,loop=True)   # plays music in background

Credits

Bhavithiran

Bhavithiran

16 projects • 7 followers
SC Lim

SC Lim

13 projects • 13 followers
Husband · Dad | Loves tinkering & making

Comments