I am making an assignment using micropython, i am making a radar gun that uses the accelerometer on one microbit and sends the speed to another microbit using the radio function. Could someone please tell me why this code is not working like i want it to.
from microbit import *
import radio
radio.on()
radio.config(group=23)
while True:
x = accelerometer.get_values()
if x > 1000:
if x <= 100:
display.scroll('10km/hr')
sleep(5000)
elif x <= 200:
display.scroll('20km/hr')
sleep(5000)
elif x <= 300:
display.scroll('30km/hr')
sleep(5000)
elif x <= 400:
display.scroll('40km/hr')
sleep(5000)
elif x <= 500:
display.scroll('50km/hr')
sleep(5000)
elif x <= 600:
display.scroll('60km/hr')
sleep(5000)
elif x <= 700:
display.scroll('70km/hr')
sleep(5000)
elif x <= 800:
display.scroll('80km/hr')
sleep(5000)
elif x <= 900:
display.scroll('90km/hr')
sleep(5000)
elif x > 1000:
display.scroll('max')
sleep(5000)
else:
display.scroll("under")
Help with assignment
Re: Help with assignment
Without indentation, it's hard to tell exactly what your code is.
But these two lines look suspicious to me:
If the second if is inside the first if (this is the only way I can see that this code would be valid python), then the second if will never be true.
But these two lines look suspicious to me:
Code: Select all
if x > 1000:
if x <= 100:
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Help with assignment
I'm puzzled The accelerometer produces acceleration values. To derive velocity from acceleration you surely need to perform an integration.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Help with assignment
It's not an instant value either. x = 1024 = 1g ~= 35kph/spythoncoder wrote:I'm puzzled The accelerometer produces acceleration values. To derive velocity from acceleration you surely need to perform an integration.
This smells very much like a case of "not even wrong".
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Help with assignment
Quite I could have written a screed on the actual requirements and the probability of achieving any semblance of accuracy, but the first step is to get the dimensional analysis looking plausibleLysenko wrote:...This smells very much like a case of "not even wrong".
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 168
- Joined: Tue Nov 07, 2017 11:45 pm
Re: Help with assignment
Bug 1: x=accelerometer.get_values()
Should read x=accelerometer.get_x()
Bug 2:aswell as display.scroll(...) you need to use radio.send("message") also a consumer micro:bit will need message =radio.receive()
Are [code] [/code] tags not valid on this BB
Should read x=accelerometer.get_x()
Bug 2:aswell as display.scroll(...) you need to use radio.send("message") also a consumer micro:bit will need message =radio.receive()
Are [code] [/code] tags not valid on this BB