Hi
I am currently trying to use this code in order to create different sounds when the microbit is tilted in a different direction. However, it isnt working...can anyone help?
from micro bit import *
import music
on = False
initial = 1000
while True:
if button_a.is_pressed():
on = True
while on:
if accelerometer.get_y() >10:
initial +=100
music.pitch(initial,100)
elif accelerometer.get_y() <10:
initial -=100
music.pitch(initial,100)
else:
music.pitch(initial,100)
if initial >4000:
initial = 4000
if initial < 100:
initial = 100
if button_b.is_pressed():
on = False
sleep(100)
microbit micropython help
Re: microbit micropython help
What do you mean exactly by "not working"?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: microbit micropython help
The first line looks wrong to me. Should microbit be one word?
I'm guessing the indentation should look like this:
I'm unfamiliar with the micro:bit but are you sure the units of sleep() are milliseconds rather than seconds? Does your indentation match mine? Do you get an error message and if so what is it?
I'm guessing the indentation should look like this:
Code: Select all
from microbit import *
import music
on = False
initial = 1000
while True:
if button_a.is_pressed():
on = True
while on:
if accelerometer.get_y() >10:
initial +=100
music.pitch(initial,100)
elif accelerometer.get_y() <10:
initial -=100
music.pitch(initial,100)
else:
music.pitch(initial,100)
if initial >4000:
initial = 4000
if initial < 100:
initial = 100
if button_b.is_pressed():
on = False
sleep(100)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: microbit micropython help
You can see the original indentation of the code by viewing the page source -- just a trick.