from machine import Pin, I2C, Timer
from ssd1306 import SSD1306_I2C
from framebuf import FrameBuffer, MONO_HLSB
import gc
from rede import Rede
from requests import get
from time import localtime, time, sleep_ms
from ntptime import settime
grana='https://economia.awesomeapi.com.br/json/last/USD-BRL'
r = Rede("Wokwi-GUEST", "", conecta=False)
r.conectar(tentativas=40, intervalo=500)
try:
if r.conectado:
settime()
except OSError as e:
print ("Deu ruim")
print (e)
ts = localtime()
print(ts)
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=400000) # I2C no ESP32
oled_width = 128
oled_height = 64
oled = SSD1306_I2C(oled_width, oled_height, i2c)
def update(t):
global atualiza
atualiza = True
def cotar():
global grana
r=get(grana)
print (r.status_code)
conteudo = r.text()
print(conteudo)
#resultado = r.json()['USDBRL']
#for k in resultado:
#print (f'{k}: {resultado[k]}')
#oled.fill(0) # Limpa o display
#oled.text(m, 10, 10) # Escreve no display nas coordenadas x e y
#oled.show()
tim = Timer(0)
tim.init(period=60000, mode=Timer.PERIODIC, callback=cotar)
atualiza = True
while True:
if atualiza:
cotar()
sleep_ms(10)
atualiza = False
Loading
aitewinrobot-esp32c3-supermini
aitewinrobot-esp32c3-supermini