def update(t=None): r = req.get(apiURL) obj = ujson.loads(r.text) city = obj['name'] icon = obj['weather'][0]['icon'] temp = int(obj['main']['temp'] - 273.15) humid = obj['main']['humidity'] path = checkIcon(icon + '.bin') f = open(path, 'rb') buf = f.read() f.close() oled.fill(0) fb = framebuf.FrameBuffer(bytearray(buf), 48, 48, framebuf.MVLSB) oled.text(city, 0, 0) oled.blit(fb, 0, 15) dsp = bigSymbol.Symbol(oled) dsp.text(str(temp) + 'c', 60, 20) dsp.text(str(humid) + '%', 60, 45) oled.show()
# -*- coding: utf-8 -*- """ 程式說明請參閱12-33頁 """ import bigSymbol from machine import Pin, I2C import ssd1306 import dht import time d = dht.DHT11(Pin(13)) i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000) oled = ssd1306.SSD1306_I2C(128, 64, i2c) dsp = bigSymbol.Symbol(oled) dsp.clear() dsp.temp(0, 18) dsp.humid(0, 38) interval = 3000 def readDHT(): d.measure() temp = d.temperature() t = '{:02}c'.format(temp) humid = d.humidity() h = '{:02}%'.format(humid) return (t, h)