GADGET RECIPE

Gadget Recipe

LED記憶ゲーム

タグ:

, , , ,

パーツ

部品名 仕様 数量
Arduino Arduino UNO R3
USBケーブル USBケーブル2.0  A-Bタイプ
LED
LED
LED
抵抗 1kΩ
半固定ボリューム 10kΩ
スイッチ タクトスイッチ
ブザー 圧電スピーカー
ブレッドボード 中型
ジャンパー線 オス−オス 10cm
ジャンパー線 オス−オス 12

作り方

1 回路図に従って接続します。
2 プログラムを書き込みます。
3 動作を確認します。

接続図

ソースコード

from machine import RTC
import ntptime
import time
import urequests
import ujson

def do_connect(ssid, password):
    import network
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...', ssid)
        wlan.connect(ssid, password)
        while not wlan.isconnected():
            print(".", end="")
            time.sleep_ms(200)
            
    print('network config:', wlan.ifconfig())
    

SERVER_URL = "api.openweathermap.org/data/2.5/weather"
API_KEY = "b2f8ca9d62d6aa46fb38d00e32d7e809"
CITY_NAME = "tokyo"
CONVERT_C = 273.15

do_connect("TP-Link_C848", "27363447")

param = "?q="+ CITY_NAME + "&appid=" + API_KEY
url = "https://" + SERVER_URL + param
res = urequests.get(url)
json_res = res.json()
print(json_res)
print("天気: ", json_res["weather"][0]["main"])
print("最低気温: ", round(json_res["main"]["temp_min"] - CONVERT_C, 1), "℃")
print("最高気温: ", round(json_res["main"]["temp_max"] - CONVERT_C, 1), "℃")
print("湿度: ", json_res["main"]["humidity"],"%")
print("気圧: ", json_res["main"]["pressure"],"hPa")

res.close()