Skip to content

Instantly share code, notes, and snippets.

@benevpi benevpi/code.py
Created Nov 1, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.