Shop Learn
Transferring code from MakeCode to microbit.python.org — Parallax Forums

Transferring code from MakeCode to microbit.python.org

MatthewG781MatthewG781 Posts: 1
edited 2021-10-11 17:06 in micro:bit

Hello everyone first time poster here. Im currently taking a robotics class at my university and am trying to figure why when I use MakeCode to run a simulation for the microbit board it works but when I transfer my code to microbit.python.org it comes up with the last line being an error. My project is to use the micobit board in any way to measure an increase in water elevation so. I decided to use the built in accelerometer as my measuring device.

I plan on replacing the show LED part of the code with some code that will light up an actual green, yellow, and red LED on the cyberbot board (most likely the ports being 0,2,4). I also plan on replacing the mealody part of the code with activating port 22 on the board as well.

Anyone know why when I run the code in the microbit.python.org it says the last line there is an error?
I like using MakeCode due to the visual block code building style it has. Here is a link to the MakeCode, https://makecode.microbit.org/_MtchesHz6C1x.

x = 0

def on_forever():
global x
x = input.acceleration(Dimension.X)
if x <= 0:
serial.write_line("Water Level Good")
basic.show_leds("""
# # # # .
# . . . .
# . # # #
# . . # .
# # # # .
""")
elif x == Math.constrain(x, 5, 512):
basic.show_leds("""
# . . . #
. # . # .
. . # . .
. . # . .
. . # . .
""")
serial.write_line("Water Level Rising")
music.play_melody("C5 - - C5 - - C5 - ", 120)
else:
basic.show_leds("""
# # # . .
# . # . .
# # # . .
# . # . .
# . . # .
""")
serial.write_line("Water Level Critical")
music.play_melody("C5 - C5 - C5 - C5 - ", 120)
basic.forever(on_forever)

Sign In or Register to comment.