【雕爷学编程】MicroPython动手做(33)——物联网之天气预报3

天气(自然现象)
是指某一个地区距离地表较近的大气层在短时间内的具体状态。而天气现象则是指发生在大气中的各种自然现象,即某瞬时内大气中各种气象要素(如气温、气压、湿度、风、云、雾、雨、闪、雪、霜、雷、雹、霾等)空间分布的综合表现。

天气过程就是一定地区的天气现象随时间的变化过程。各种天气系统都具有一定的空间尺度和时间尺度,而且各种尺度系统间相互交织、相互作用。许多天气系统的组合,构成大范围的天气形势,构成半球甚至全球的大气环流。天气系统总是处在不断新生、发展和消亡过程中,在不同发展阶段有着其相对应的天气现象分布。

在这里插入图片描述
天气预报
是应用大气变化的规律,根据当前及近期的天气形势,对某一地未来一定时期内的天气状况进行预测。它是根据对卫星云图和天气图的分析,结合有关气象资料、地形和季节特点、群众经验等综合研究后作出的。如我国中央气象台的卫星云图,就是我国制造的“风云一号”气象卫星摄取的。利用卫星云图照片进行分析,能提高天气预报的准确率。天气预报就时效的长短通常分为三种:短期天气预报(2~3天)、中期天气预报(4~9天),长期天气预报(10~15天以上),中央电视台每天播放的主要是短期天气预报。

天气预报的主要内容是一个地区或城市未来一段时期内的阴晴雨雪、最高最低气温、风向和风力及特殊的灾害性天气。就中国而言,气象台准确预报寒潮、台风、暴雨等自然灾害出现的位置和强度,就可以直接为工农业生产和群众生活服务。天气预报是根据气象观测资料,应用天气学、动力气象学、统计学的原理和方法,对某区域或某地点未来一定时段的天气状况作出定性或定量的预测。它是大气科学研究的一个重要目标。对人们生活有重要意义。

在这里插入图片描述
在这里插入图片描述

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

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

#MicroPython动手做(33)——物联网之天气预报
#使用三轴传感器选择城市天气预报from mpython import *
import urequests
import network
import ntptime
import music
import jsonbrightness=9weather_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()

Mind+ 实验图形编程

在这里插入图片描述

10、全球天气API平台

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

在这里插入图片描述
在这里插入图片描述

注册全球天气API平台账号

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

在这里插入图片描述

登录全球天气API平台

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

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

在这里插入图片描述

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 jsontouch_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():passdef timer12_tick(_):global _status_p, _status_y, _status_t, _status_h, _status_o, _status_ntry:touchPad_P.read();passexcept:returnif 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=9weather_serveraddr = "http://www.tianqiapi.com"weather_appid = "85215611"weather_appsecret = "Kx8r5ZCY "# 事件回调函数
def on_touchpad_P_pressed():global g_my_variablemusic.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_variablemusic.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_variablemusic.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_variablemusic.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_variablemusic.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_variablemusic.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()

Mind+ 实验图形编程

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

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

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/22617.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【基础类】—DOM事件系统性学习

一、基本概念&#xff1a;DOM事件的级别 // DOM0 element.onclickfunction(){} // DOM2, 新增了冒泡和捕获 element.addEventListener(click,function(){}, false) // DOM3, 新增更多事件类型 鼠标、键盘等 element.addEventListener(keyup,function(){}, false)二、DOM事件模…

JVM 学习

这里写目录标题 说一说JVM的内存区域JVM 内存模型volatile的使用及其原理Java中类加载过程是什么样的?方法区内存溢出怎么处理?谈谈动态年龄判断哪些是 GC Roots?强引用、软引用、弱引用、虚引用是什么,有什么区别?工作中常用的 JVM 配置参数有哪些?谈谈对 OOM 的认识谈谈…

解决在mybatis中使用class属性绑定映射文件出现的异常问题~

如下所示&#xff0c;当我在XML文件中通过class属性配置其mapper文件时&#xff0c;出现下述错误 <mappers><mapper class"mappers.userMapper"/> </mappers>错误描述&#xff1a; 解决方法如下所示&#xff1a;在pom.xml文件中添加下述代码 <…

网络安全进阶学习第十一课——MySQL手工注入(2)

文章目录 一、UA注入1、原理2、靶场演示&#xff1a;1&#xff09;一旦页面出现如下现状&#xff0c;就可以使用UA注入2&#xff09;BP抓包3&#xff09;修改User-Agent 二、referer注入1、原理2、靶场演示&#xff1a;1&#xff09;使用BP抓包2&#xff09;修改Referer 三、DN…

计算机视觉的延伸整理

计算机视觉是一门涉及数字图像处理、模式识别和机器学习等技术的交叉学科&#xff0c;旨在将计算机技术应用于对视觉信息的理解和处理。其主要研究内容包括图像和视频处理、目标检测和跟踪、三维重建、人脸识别、自动驾驶等。计算机视觉已经被广泛应用于医学影像分析、安防监控…

C#IEnumberable<>

在C#中&#xff0c;IEnumerable<>是一个泛型接口&#xff0c;用于表示一个可枚举的集合。它定义了一个用于遍历集合元素的枚举器&#xff08;enumerator&#xff09;。通过实现IEnumerable<>接口&#xff0c;我们可以使用foreach语句或LINQ查询等方式来迭代访问集合…

element-ui 图片上传 及 quillEditor富文本(图片视频上传)

<template><div class"card" style"overflow: hidden; padding-bottom: 10px"><div style"padding: 20px 20px 0 20px"><span class"title_top"><span class"top_icon"></span>基本信息…

SQL基础复习与进阶

SQL进阶 文章目录 SQL进阶关键字复习ALLANYEXISTS 内置函数ROUND&#xff08;四舍五入&#xff09;TRUNCATE&#xff08;截断函数&#xff09;SEILING&#xff08;向上取整&#xff09;FLOOR&#xff08;向下取整&#xff09;ABS&#xff08;获取绝对值&#xff09;RAND&#x…

RPC原理与Go RPC详解

文章目录 RPC原理与Go RPC什么是RPC本地调用RPC调用HTTP调用RESTful API net/rpc基础RPC示例基于TCP协议的RPC使用JSON协议的RPCPython调用RPC RPC原理 RPC原理与Go RPC 什么是RPC RPC&#xff08;Remote Procedure Call&#xff09;&#xff0c;即远程过程调用。它允许像调用…

React Native元素旋转一定的角度

mMeArrowIcon: {fontSize: 30, color: #999, transform: [{rotate: 180deg}]},<Icon name"arrow" style{styles.mMeArrowIcon}></Icon>参考链接&#xff1a; https://reactnative.cn/docs/transforms https://chat.xutongbao.top/

ID生成方案总结

分布式ID生成方案 UUID数据库自增号段模式Redis实现雪花算法&#xff08;SnowFlake&#xff09;百度Uidgenerator美团Leaf滴滴TinyID 本文重点介绍能够ID自增的Leaf和TinyID 号段模式 这种模式也是现在生成分布式ID的一种方法&#xff0c;实现思路是会从数据库获取一个号段…

MikTex+TexStudio踩坑记

首先&#xff0c;去这两个的官网&#xff0c;下载安装&#xff0c;都没问题。 第二&#xff0c;记得以管理员方式运行程序&#xff0c;可能会少很多麻烦 第三&#xff0c;编译的时候&#xff0c;命令行提示错误&#xff1a; So far, no MiKTeX administrator has checked fo…

AcWing 24:机器人的运动范围 ← BFS、DFS

【题目来源】https://www.acwing.com/problem/content/description/22/【题目描述】 地上有一个 m 行和 n 列的方格&#xff0c;横纵坐标范围分别是 0∼m−1 和 0∼n−1。 一个机器人从坐标 (0,0) 的格子开始移动&#xff0c;每一次只能向左&#xff0c;右&#xff0c;上&#…

【雕爷学编程】Arduino动手做(182)---DRV8833双路电机驱动模块2

37款传感器与执行器的提法&#xff0c;在网络上广泛流传&#xff0c;其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块&#xff0c;依照实践出真知&#xff08;一定要动手做&#xff09;的理念&#xff0c;以学习和交流为目的&am…

【LangChain】Prompts之Prompt templates

Prompts 编程模型的新方法是通过提示(prompts)。 prompts是指模型的输入。该输入通常由多个组件构成。 LangChain 提供了多个类和函数&#xff0c;使构建和使用prompts变得容易。 Prompt templates(提示模板): 参数化模型输入Example selectors(选择器示例): 动态选择要包含在…

EventBus 开源库学习(一)

一、概念 EventBus是一款在 Android 开发中使用的发布-订阅事件总线框架&#xff0c;基于观察者模式&#xff0c;将事件的接收者和发送者解耦&#xff0c;简化了组件之间的通信&#xff0c;使用简单、效率高、体积小。 一句话&#xff1a;用于Android组件间通信的。 二、原理…

TypeScript最新语法总结

注意注意&#xff01;&#xff01;&#xff01;本文介绍的是最新的TypeScript4的重要语法 第一部分&#xff1a;TypeScript的简介 TypeScript 是由微软开发的一款开源的编程语言&#xff0c;TypeScript 是 Javascript 的超集&#xff0c;遵循最新的 ES6、ES5 规范&#xff0c…

做好“关键基础设施提供商”角色,亚马逊云科技加快生成式AI落地

一场关于生产力的革命已在酝酿之中。全球管理咨询公司麦肯锡在最近的报告《生成式人工智能的经济潜力&#xff1a;下一波生产力浪潮》中指出&#xff0c;生成式AI每年可能为全球经济增加2.6万亿到4.4万亿美元的价值。在几天前的亚马逊云科技纽约峰会中&#xff0c;「生成式AI」…

动手学深度学习(二)线性神经网络

推荐课程&#xff1a;跟李沐学AI的个人空间-跟李沐学AI个人主页-哔哩哔哩视频 回归任务是指对连续变量进行预测的任务。 一、线性回归 线性回归模型是一种常用的统计学习方法&#xff0c;用于分析自变量与因变量之间的关系。它通过建立一个关于自变量和因变量的线性方程&…

分布式协议与算法——拜占庭将军问题

拜占庭将军问题 背景&#xff1a;以战国时期为背景 战国时期&#xff0c;齐、楚、燕、韩、赵、魏、秦七雄并立&#xff0c;后来秦国的势力不断强大起来&#xff0c;成了东方六国的共同威胁。于是&#xff0c;这六个国家决定联合&#xff0c;全力抗秦&#xff0c;免得被秦国各个…