Speed and Distance Measuring
Posted: Sat Dec 05, 2015 2:32 pm
I looking for help to concoct a program that will do the following things with the sense hat:
1. Output speed in MPH
2. Output distance in feet
My code (not accurate):
Kratos
1. Output speed in MPH
2. Output distance in feet
My code (not accurate):
Code: Select all
#Description :This program will print your speed and distance usng the sense hat
#Author: Kratos
#Version: 12.5.15
#Notes: Output is in meters and meters per second
# Speed = distance / time
#distance = 0.5 * acceleration * (time * time)
import time
from sense_hat import SenseHat
sense = SenseHat()
green = 0, 255, 0
print_on_hat = False #set to True if you want the values dislpayed on the hat
ti = time.time()
init_speed = 0
while True:
new_time = time.time()
raw = sense.get_accelerometer_raw()
y = raw['y']
distance = (init_speed + 0.5*y*((ti - time.time())*(ti - time.time()))*3.2808)
speed = distance / new_time
init_speed = speed
if print_on_hat == False:
print('Your distance: %s' %distance)
print('Your speed: %s' %speed)
if print_on_hat == True:
sense.show_message('D: %s' %distance, text_colour=green)
sense.show_message('S: %s' %speed, text_colour=green)