Sunday, 17 March 2019

Microbit Controlled Rollercoaster


Always keen to see what else I can motorise with Lego I bought the necessary bits to motorise a Lego roller coaster. I bought only the carts, track and chain links from brick link. link

I borrowed the Ferris Wheel car parts from my daughters Ferris wheel that I had previously "borrowed" to motorise. (See below)

I used some basic cogs and Lego Technic bits to drive the cars up the main ramp(see below). 


I reused the Micro:bit motor controller and Micro:bit I had used previously on the Micro:bit Express and Ferris Wheel blogs(See below).


I used the following code:
from microbit import *

def stop():
    pin8.write_analog(1023)
    pin12.write_analog(1023)

def forward(speed):
    pin8.write_analog(speed)
    pin12.write_digital(0)
    display.scroll(speed)

    
speed = 400 

while True:
    
    if button_a.was_pressed():
        display.scroll('F')
        forward(speed)
    
    if button_b.was_pressed():
        display.scroll('S')
        stop()

Updated code for incremental speed control:

from microbit import *

def stop():
    pin8.write_analog(1023)
    pin12.write_analog(1023)

def forward(speed):
    pin8.write_analog(speed)
    pin12.write_digital(0)
    display.scroll(speed)

    
speed = 400 

while True:
    
    if button_a.was_pressed():
        
        
        speed = speed + 50
        msg = "F" + str(speed)
        display.scroll(msg)
        if speed > 1000:
            speed = 400
        forward(speed)
    
    if button_b.was_pressed():
        display.scroll('S')
        stop()


Over :)