3386

帖子

0

TA的资源

五彩晶圆(中级)

21
 

9、使用三轴传感器选择城市天气预报

 

向前倾斜为安徽合肥,向后为福建福州
向左为上海,向右为北京

 

  • #MicroPython动手做(33)——物联网之天气预报
  • #使用三轴传感器选择城市天气预报
  • from mpython import *
  • import urequests
  • import network
  • import ntptime
  • import music
  • import json
  • brightness=9
  • weather_serveraddr = "http://server.mindplus.top"
  • weather_appid = "31982666"
  • weather_appsecret = "E6MtBcxQ"
  • def weather_getWeather(_weather, _city):
  • if weather_serveraddr=="http://www.tianqiapi.com":
  • nowResult = urequests.get(weather_serveraddr+"/api/?appid="+weather_appid+"&appsecret="+weather_appsecret+"&version=v6&cityid="+_city)
  • json=nowResult.json()
  • nowResult.close()
  • return json[_weather]
  • else:
  • nowResult = urequests.get(weather_serveraddr+"/api/weather/?appid="+weather_appid+"&appsecret="+weather_appsecret+"&version=v6&cityid="+_city)
  • json=nowResult.json()
  • nowResult.close()
  • return json[_weather]
  • my_wifi = wifi()
  • my_wifi.connectWiFi("zh","zy1567")
  • while not (my_wifi.sta.isconnected()):
  • pass
  • rgb[1] = (0*brightness//9, 102*brightness//9, 0*brightness//9)
  • rgb.write()
  • music.pitch(165, 50)
  • ntptime.settime(8, "ntp.ntsc.ac.cn")
  • while True:
  • if (accelerometer.get_x() < -0.3):
  • music.pitch(196, 50)
  • oled.fill(0)
  • oled.DispChar("安徽 合肥", 0, (1-1)*16, 1)
  • oled.DispChar(weather_getWeather("wea", "101220101"), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101220101"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101220101"))), 0, (4-1)*16, 1)
  • oled.show()
  • if (accelerometer.get_x() > 0.3):
  • music.pitch(262, 50)
  • oled.fill(0)
  • oled.DispChar("福建 福州", 0, (1-1)*16, 1)
  • oled.DispChar(weather_getWeather("wea", "101230101"), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101230101"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101230101"))), 0, (4-1)*16, 1)
  • oled.show()
  • if (accelerometer.get_y() > 0.3):
  • music.pitch(392, 50)
  • oled.fill(0)
  • oled.DispChar("上海", 0, (1-1)*16, 1)
  • oled.DispChar(weather_getWeather("wea", "101020100"), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101020100"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101020100"))), 0, (4-1)*16, 1)
  • oled.show()
  • if (accelerometer.get_y() < -0.3):
  • music.pitch(659, 50)
  • oled.fill(0)
  • oled.DispChar("北京", 0, (1-1)*16, 1)
  • oled.DispChar(weather_getWeather("wea", "101010100"), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101010100"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101010100"))), 0, (4-1)*16, 1)
  • oled.show()

 

 

 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

22
 

Mind+  实验图形编程

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

23
 

10、全球天气API平台

 

链接:http://www.tianqiapi.com

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

24
 

注册全球天气API平台账号

 

链接:http://www.tianqiapi.com/user/register

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

25
 

登录全球天气API平台

 

链接:http://www.tianqiapi.com/user/index

激活账号,获取APPID和APPSecret(密钥)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

26
 

11、六位触摸按键选择城市天气预报

 

P 上海   Y 福州   T 北京   H 重庆   O 深圳  N 济南

 

  • #MicroPython动手做(33)——物联网之天气预报
  • #六位触摸按键选择城市天气预报
  • from machine import Timer
  • from mpython import *
  • import urequests
  • import network
  • import ntptime
  • import music
  • import json
  • touch_threshold = {'P': 400, 'Y': 400, 'T': 400, 'H': 400, 'O': 400, 'N': 400}
  • tim12 = Timer(12)
  • _status_p = _status_y = _status_t = _status_h = _status_o = _status_n = 0
  • def on_touchpad_P_pressed():pass
  • def on_touchpad_P_unpressed():pass
  • def on_touchpad_Y_pressed():pass
  • def on_touchpad_Y_unpressed():pass
  • def on_touchpad_T_pressed():pass
  • def on_touchpad_T_unpressed():pass
  • def on_touchpad_H_pressed():pass
  • def on_touchpad_H_unpressed():pass
  • def on_touchpad_O_pressed():pass
  • def on_touchpad_O_unpressed():pass
  • def on_touchpad_N_pressed():pass
  • def on_touchpad_N_unpressed():pass
  • def timer12_tick(_):
  • global _status_p, _status_y, _status_t, _status_h, _status_o, _status_n
  • try:
  • touchPad_P.read();pass
  • except:
  • return
  • if touchPad_P.read() < touch_threshold['P']:
  • if 1 != _status_p:_status_p = 1;on_touchpad_P_pressed()
  • elif 0 != _status_p:_status_p = 0;on_touchpad_P_unpressed()
  • if touchPad_Y.read() < touch_threshold['Y']:
  • if 1 != _status_y:_status_y = 1;on_touchpad_Y_pressed()
  • elif 0 != _status_y:_status_y = 0;on_touchpad_Y_unpressed()
  • if touchPad_T.read() < touch_threshold['T']:
  • if 1 != _status_t:_status_t = 1;on_touchpad_T_pressed()
  • elif 0 != _status_t:_status_t = 0;on_touchpad_T_unpressed()
  • if touchPad_H.read() < touch_threshold['H']:
  • if 1 != _status_h:_status_h = 1;on_touchpad_H_pressed()
  • elif 0 != _status_h:_status_h = 0;on_touchpad_H_unpressed()
  • if touchPad_O.read() < touch_threshold['O']:
  • if 1 != _status_o:_status_o = 1;on_touchpad_O_pressed()
  • elif 0 != _status_o:_status_o = 0;on_touchpad_O_unpressed()
  • if touchPad_N.read() < touch_threshold['N']:
  • if 1 != _status_n:_status_n = 1;on_touchpad_N_pressed()
  • elif 0 != _status_n:_status_n = 0;on_touchpad_N_unpressed()
  • def weather_getWeather(_weather, _city):
  • if weather_serveraddr=="http://www.tianqiapi.com":
  • nowResult = urequests.get(weather_serveraddr+"/api/?appid="+weather_appid+"&appsecret="+weather_appsecret+"&version=v6&cityid="+_city)
  • json=nowResult.json()
  • nowResult.close()
  • return json[_weather]
  • else:
  • nowResult = urequests.get(weather_serveraddr+"/api/weather/?appid="+weather_appid+"&appsecret="+weather_appsecret+"&version=v6&cityid="+_city)
  • json=nowResult.json()
  • nowResult.close()
  • return json[_weather]
  • brightness=9
  • weather_serveraddr = "http://www.tianqiapi.com"
  • weather_appid = "85215611"
  • weather_appsecret = "Kx8r5ZCY "
  • # 事件回调函数
  • def on_touchpad_P_pressed():
  • global g_my_variable
  • music.pitch(147, 500)
  • oled.fill(0)
  • oled.DispChar("上海", 0, (1-1)*16, 1)
  • oled.DispChar(weather_getWeather("wea", "101020100"), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101020100"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101020100"))), 0, (4-1)*16, 1)
  • oled.show()
  • def on_touchpad_H_pressed():
  • global g_my_variable
  • music.pitch(175, 500)
  • oled.fill(0)
  • oled.DispChar("重庆", 0, (1-1)*16, 1)
  • oled.DispChar(weather_getWeather("wea", "101040100"), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101040100"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101040100"))), 0, (4-1)*16, 1)
  • oled.show()
  • def on_touchpad_Y_pressed():
  • global g_my_variable
  • music.pitch(247, 500)
  • oled.fill(0)
  • oled.DispChar("福州", 0, (1-1)*16, 1)
  • oled.DispChar((str("天气情况:") + str(weather_getWeather("wea", "101230101"))), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101230101"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101230101"))), 0, (4-1)*16, 1)
  • oled.show()
  • def on_touchpad_O_pressed():
  • global g_my_variable
  • music.pitch(196, 500)
  • oled.fill(0)
  • oled.DispChar("深圳", 0, (1-1)*16, 1)
  • oled.DispChar(weather_getWeather("wea", "101280601"), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101280601"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101280601"))), 0, (4-1)*16, 1)
  • oled.show()
  • def on_touchpad_T_pressed():
  • global g_my_variable
  • music.pitch(165, 500)
  • oled.fill(0)
  • oled.DispChar("北京", 0, (1-1)*16, 1)
  • oled.DispChar(weather_getWeather("wea", "101010100"), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101010100"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101010100"))), 0, (4-1)*16, 1)
  • oled.show()
  • def on_touchpad_N_pressed():
  • global g_my_variable
  • music.pitch(220, 500)
  • oled.fill(0)
  • oled.DispChar("济南", 0, (1-1)*16, 1)
  • oled.DispChar(weather_getWeather("wea", "101120101"), 0, (2-1)*16, 1)
  • oled.DispChar((str("最低温度:") + str(weather_getWeather("tem2", "101120101"))), 0, (3-1)*16, 1)
  • oled.DispChar((str("最高温度:") + str(weather_getWeather("tem1", "101120101"))), 0, (4-1)*16, 1)
  • oled.show()
  • tim12.init(period=100, mode=Timer.PERIODIC, callback=timer12_tick)
  • my_wifi = wifi()
  • my_wifi.connectWiFi("zh","zy1567")
  • while not (my_wifi.sta.isconnected()):
  • pass
  • rgb[1] = (0*brightness//9, 102*brightness//9, 0*brightness//9)
  • rgb.write()
  • music.pitch(131, 50)
  • ntptime.settime(8, "ntp.ntsc.ac.cn")
  • oled.fill(0)
  • oled.DispChar("触摸按键选城市", 0, (1-1)*16, 1)
  • oled.DispChar("P 上海 Y 福州", 0, (2-1)*16, 1)
  • oled.DispChar("T 北京 H 重庆", 0, (3-1)*16, 1)
  • oled.DispChar("O 深圳 N 济南", 0, (4-1)*16, 1)
  • oled.show()

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

27
 

Mind+  实验图形编程

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

28
 

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

29
 

六位触摸按键选择城市天气预报

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

30
 

目录清单
MicroPython动手做(01)——春节后入手了一块K210芯片AI开发板 
https://bbs.eeworld.com.cn/thread-1115786-1-1.html

MicroPython动手做(02)——尝试搭建K210开发板的IDE环境
https://bbs.eeworld.com.cn/thread-1115831-1-1.html

MicroPython动手做(03)——零基础学MaixPy之开机运行
https://bbs.eeworld.com.cn/thread-1116184-1-1.html

MicroPython动手做(04)——零基础学MaixPy之基本示例
https://bbs.eeworld.com.cn/thread-1116438-1-1.html

MicroPython动手做(05)——零基础学MaixPy之LCD液晶屏
https://bbs.eeworld.com.cn/thread-1116577-1-1.html

MicroPython动手做(06)——零基础学MaixPy之单目摄像头
https://bbs.eeworld.com.cn/thread-1116591-1-1.html

MicroPython动手做(07)——零基础学MaixPy之机器视觉
https://bbs.eeworld.com.cn/thread-1116617-1-1.html

MicroPython动手做(08)——零基础学MaixPy之识别颜色 
https://bbs.eeworld.com.cn/thread-1116662-1-1.html

MicroPython动手做(09)——零基础学MaixPy之人脸识别
https://bbs.eeworld.com.cn/thread-1116720-1-1.html

MicroPython动手做(10)——零基础学MaixPy之神经网络KPU
https://bbs.eeworld.com.cn/thread-1116925-1-1.html

MicroPython动手做(11)——搭建掌控板IDE环境
https://bbs.eeworld.com.cn/thread-1117964-1-1.html

MicroPython动手做(12)——掌控板之Hello World
https://bbs.eeworld.com.cn/thread-1118180-1-1.html

MicroPython动手做(13)——掌控板之RGB三色灯 
https://bbs.eeworld.com.cn/thread-1118275-1-1.html

MicroPython动手做(14)——掌控板之OLED屏幕
https://bbs.eeworld.com.cn/thread-1118389-1-1.html

MicroPython动手做(15)——掌控板之AB按键
https://bbs.eeworld.com.cn/thread-1118496-1-1.html

MicroPython动手做(16)——掌控板之图片图像显示
https://bbs.eeworld.com.cn/thread-1118945-1-1.html

MicroPython动手做(17)——掌控板之触摸引脚
https://bbs.eeworld.com.cn/thread-1119462-1-1.html

MicroPython动手做(18)——掌控板之声光传感器
https://bbs.eeworld.com.cn/thread-1119583-1-1.html

MicroPython动手做(19)——掌控板之蜂鸣器与音乐
https://bbs.eeworld.com.cn/thread-1119668-1-1.html

MicroPython动手做(20)——掌控板之三轴加速度
https://bbs.eeworld.com.cn/thread-1119998-1-1.html

MicroPython动手做(21)——掌控板之磁场传感器
https://bbs.eeworld.com.cn/thread-1120188-1-1.html

MicroPython动手做(22)——掌控板之无线广播
https://bbs.eeworld.com.cn/thread-1120835-1-1.html

MicroPython动手做(23)——掌控板之WiFi与蓝牙
https://bbs.eeworld.com.cn/thread-1120934-1-1.html

MicroPython动手做(24)——掌控板之拓展掌控宝 
https://bbs.eeworld.com.cn/thread-1121208-1-1.html

MicroPython动手做(25)——语音合成与语音识别
https://bbs.eeworld.com.cn/thread-1123752-1-1.html

MicroPython动手做(26)——物联网之OneNET
https://bbs.eeworld.com.cn/thread-1125172-1-1.html

MicroPython动手做(27)——物联网之微信小程序
https://bbs.eeworld.com.cn/thread-1125520-1-1.html

MicroPython动手做(28)——物联网之Yeelight
https://bbs.eeworld.com.cn/thread-1125939-1-1.html

MicroPython动手做(29)——物联网之SIoT
https://bbs.eeworld.com.cn/thread-1126090-1-1.html

 MicroPython动手做(30)——物联网之Blynk

https://bbs.eeworld.com.cn/thread-1126427-1-1.html

MicroPython动手做(31)——物联网之Easy IoT 

https://bbs.eeworld.com.cn/thread-1126903-1-1.html

MicroPython动手做(32)——物联网之MQTT
https://bbs.eeworld.com.cn/thread-1128464-1-1.html

MicroPython动手做(33)——物联网之天气预报
https://bbs.eeworld.com.cn/thread-1128721-2-1.html

MicroPython动手做(34)——通用传感器的综合运用
https://bbs.eeworld.com.cn/thread-1129058-1-1.html

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
立即报名 | 2025 瑞萨电子工业以太网技术日即将开启!
3月-4月 深圳、广州、北京、苏州、西安、上海 走进全国6城
2025瑞萨电子工业以太网技术巡回沙龙聚焦工业4.0核心需求,为工程师与企业决策者提供实时通信技术最佳解决方案。
预报从速,好礼等您拿~

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表