Created
November 1, 2019 17:22
-
-
Save benevpi/f2c9a977289965690c3af4440c7d5e05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import board | |
import neopixel | |
from adafruit_ble.uart_server import UARTServer | |
from time import sleep | |
import adafruit_thermistor | |
import analogio | |
import math | |
from adafruit_bluefruit_connect.packet import Packet | |
from adafruit_bluefruit_connect.location_packet import LocationPacket | |
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10) | |
uart_server = UARTServer() | |
current_long = 0 | |
current_lat = 0 | |
while True: | |
# Advertise when not connected. | |
uart_server.start_advertising() | |
while not uart_server.connected: | |
pass | |
while uart_server.connected: | |
packet = Packet.from_stream(uart_server) | |
if isinstance(packet, LocationPacket): | |
#print(packet.longitude, packet.latitude) | |
delta_long = current_long - packet.longitude | |
delta_lat = current_lat - packet.latitude | |
distance = math.sqrt((delta_long * delta_long) + (delta_lat * delta_lat)) | |
#print(distance) | |
current_long = packet.longitude | |
current_lat = packet.latitude | |
speed = distance * 100000 | |
print(speed) | |
pixels.fill((0,0,0)) | |
for i in range(0,min(speed,9)): | |
pixels[i] = (100,0,0) | |
print(i) | |
pixels.show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment