DHT22温湿度计——记录55秒温度

import dht
import network
import socket
import utime
from machine import Pin, Timer

led2 = Pin(2, Pin.OUT)
led2.value(1)
utime.sleep(10)
espht = dht.DHT22(Pin(4))
tm = Timer(10)
tm1 = Timer(11)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
dht22t = [0, 0, 0, 0, 0, 0, 0, 0, 0,[......]

继续阅读

micropython 配网上报温湿度

boot.py

import network, utime, gc, socket, ure
from machine import I2C, Pin, Timer
from sht2x import SHT2x
from simple import MQTTClient

sensor = SHT2x(I2C(scl=Pin(5), sda=Pin(4)))
led1 = Pin(2, Pin.OUT)
led1.value(1)
LED = Pin(15, Pin.OUT)
LED.value(1)
utime.sleep(10)
SERVER = "mq.tongxinmao.co[......]

继续阅读

micropython 结合mtqq上报sht20温湿度

import network, utime
from machine import I2C, Pin, Timer
from sht2x import SHT2x
from simple import MQTTClient

sensor = SHT2x(I2C(scl=Pin(5), sda=Pin(4)))
led1 = Pin(2, Pin.OUT)
led1.value(1)
LED = Pin(15, Pin.OUT)
LED.value(1)
SERVER = "mq.tongxinmao.com"
PORT = 18830
CLIENT_ID = "umqtt_sht20"

c[......]

继续阅读

python分时阶梯电价

'''每秒将 时间 及功耗传入;
湖北地区,'''
#totalPower
totalPW=0
#totalMoney
totalMy=0
#分时电量1
def PowerTime(usptime): # 输入时间得到分时系数
    # 分时电价
    '''
    20-22 180%
    9-15 149%
    7-9 100%
    15-20 100%
    22-23 100%
    23-24 48%
    0-7 48%
    '''
    atim,btim,ctim,dtim=[],[],[],[]
    for i in range(20,22)[......]

继续阅读

mircopython PWM呼吸灯

from machine import Pin, PWM, Timer
#调整dp/period控制速度
LED = PWM(Pin(0))
p = 0
dp = 4
tm = Timer(2)

def LED_set(t):
    global p, dp
    LED.duty(p)
    p += dp
    if p == 0 or p > 1023 - dp:
        dp = -dp

tm.init(period=8, mode=Timer.PERIODIC, callback=LED_set)

[……]

继续阅读

sht20测温web结合呼吸灯

boot.py

from machine import Pin, Timer, PWM, I2C
import utime
import network, gc, socket
from sht2x import SHT2x

gc.collect()
s =socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
sensor = SHT2x(I2C(scl=Pin(5), sda=Pin(4)))
led = Pin(2, Pin.OUT)
utime.sleep(10)
led.va[......]

继续阅读

【ESP8266学习】micropython实现呼吸灯

通过在PWM控制,利用延时的方法实现了一个呼吸灯。但是延时会让其它任务无法执行因此决定使用定时器实现呼吸灯。

先定义一个LED_set函数,每调用一次函数就改变一次LED的亮度,然后将它指定为定时器的回调函数,就可以方便的实现呼吸灯了。改变dp和定时器周期,可以调整呼吸灯的速度。

  1. from machine import Pin, Timer, PWM
  2. LED = PWM(Pin(15))
  3. p = 0
  4. dp = 4
  5. def LED_set(t):
  6.     global p, dp
  7.     LED.duty(p)
  8.     p += dp
  9.     if p == 0 or p > 1023 – dp:
  10.  [……]

    继续阅读

1 2 3 4 15