# import urequests # ev3 = EV3Brick() hub = PrimeHub() # Connect motor to port A and touch sensor to port S1 # pointer=Motor(Port.A) pointer = Motor('A') # touch=TouchSensor(Port.S1) touch = ForceSensor('E') #set the arrow to blue bar (minimum) to begin with # pointer.reset_angle(0) pointer.run_to_position(0) # defining the maximum and minimum temperatures shown by the dashboard # You can change the minimum and maximum temperatures based on your location. # Calculate where you should place the green (comfortable temperature) # and yellow (slightly uncomfortable temperature) bars on your design? blue_temp = 0 # minimum temperature in celsius red_temp = 40 # maximum temperature in celsius # Angle between red and blue bar. 180 degrees in our case. # It will be based on your gauge design. angle_bw_blueandred = 180 # Get the API key from openweathermap.org and replace the text YOUR_API_KEY with the key # don't remove the quotes
# This example finds and connects to a peripheral running the # UART service (e.g. ble_simple_peripheral.py). from spike import PrimeHub from spike import Motor # Do something hubprime = PrimeHub() import hub motor_drive = Motor("B") motor_steer = Motor("A") motor_steer.run_to_position(17) import bluetooth import random import struct import time import micropython import ubinascii def light(n): x = n % 5 y = n // 5 hubprime.light_matrix.set_pixel(x, y) from micropython import const _IRQ_CENTRAL_CONNECT = const(1 << 0)
from spike import PrimeHub, Motor, ForceSensor import utime hub = PrimeHub() pointer = Motor('A') touch = ForceSensor('E') pointer.run_to_position(0) #Note: not tested yet blue_temp = 0 red_temp = 40 angle_bw_blueandred = 180 def turn_pointer(): temp_in_kelvin = 300 city_name = "tester" temp_in_celsius = round(temp_in_kelvin - 273.15) print(temp_in_celsius) unit_degree = angle_bw_blueandred / (red_temp - blue_temp) turn_angle = unit_degree * temp_in_celsius pointer.run_for_degrees(20, turn_angle) return temp_in_celsius, city_name while True: temp_in_celsius, city_name = turn_pointer() if touch.is_pressed(): hub._light_matrix.write("It's " + str(temp_in_celsius) + "degree celsius in" + city_name) utime.sleep(1)