from machine import Pin, I2C
import ssd1306
from HC1SR04 import HCSR04
from time import sleep
import network
import urequests
import json
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("wokwi-GUEST", "")
while not wlan.isconnected():
pass
headers = {'Authorization': 'Bearer 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', 'Content-Type': 'application/json',}
# ESP32 Pin assignment
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
sensor = HCSR04(trigger_pin=32, echo_pin=33, echo_timeout_us=25000)
cont = 0
columna = 1
dists = []
while cont < 10:
distancia = sensor.distance_cm()
dists.append(distancia)
texto = "Distance = " + str(distancia) + "cm"
oled.init_display()
oled.text(texto, 0, cont, columna)
# oled.fill(columna)
# columna = columna + 1
# oled.scroll(0, 10)}
# cont = cont + 10
oled.show()
# print("Distancia:", distancia, "cm")
sleep(2)
cont = cont + 1
prompt = "Given the following array of distances " + str(dists) + ", ¿Is there a pattern or tendency in the distances through time?"
print(prompt)
# data = '{"model": "gpt-3.5-turbo","messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0}"
# URL = "https://api.openai.com/v1/chat/completions"
# r = urequests.post(URL, headers-headers, data=data)
# person_dict = json.loads(r.text)
# print (person_dict['choices'][0]['message']['content'])