MicroPython动手做(17)——掌控板之触摸引脚-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

123
返回列表 发新帖
楼主: eagler8

MicroPython动手做(17)——掌控板之触摸引脚

[复制链接]
 楼主| 发表于 2020-4-29 14:45 | 显示全部楼层
mPython X 图形编程

11.jpg
 楼主| 发表于 2020-4-29 15:13 | 显示全部楼层
视频:触摸按键点播六首曲子
https://v.youku.com/v_show/id_XN ... oneSokuUgc_1.dtitle

12.jpg

 楼主| 发表于 2020-6-6 17:01 | 显示全部楼层
10、六个触摸键控制的RGB颜色灯

[mw_shl_code=arduino,true]#MicroPython动手做(17)——掌控板之触摸引脚
#六个触摸键控制的RGB颜色灯

from mpython import *
import network
import time
import music
from yeelight import *
from machine import Timer

my_wifi = wifi()

my_wifi.connectWiFi("zh", "zy1567")

_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

tim12 = Timer(12)

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() < 400:
        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() < 400:
        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() < 400:
        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() < 400:
        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() < 400:
        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() < 400:
        if 1 != _status_n:_status_n = 1;on_touchpad_N_pressed()
    elif 0 != _status_n:_status_n = 0;on_touchpad_N_unpressed()

tim12.init(period=100, mode=Timer.PERIODIC, callback=timer12_tick)

def on_touchpad_P_pressed():
    global i
    time.sleep_ms(500)
    bulb.set_rgb(153, 0, 0)
    oled.DispChar("P键  红色", 38, 32, 1)
    oled.show()
    rgb.fill((int(153), int(0), int(0)))
    rgb.write()
    time.sleep_ms(1)

def on_touchpad_Y_pressed():
    global i
    time.sleep_ms(500)
    bulb.set_rgb(0, 153, 0)
    oled.DispChar("Y键  绿色", 38, 32, 1)
    oled.show()
    rgb.fill((int(0), int(153), int(0)))
    rgb.write()
    time.sleep_ms(1)

def on_touchpad_T_pressed():
    global i
    time.sleep_ms(500)
    bulb.set_rgb(51, 51, 255)
    oled.DispChar("T键  蓝色", 38, 32, 1)
    oled.show()
    rgb.fill((int(51), int(51), int(255)))
    rgb.write()
    time.sleep_ms(1)

def on_touchpad_H_pressed():
    global i
    time.sleep_ms(500)
    bulb.set_rgb(255, 102, 0)
    oled.DispChar("H键  橙色", 38, 32, 1)
    oled.show()
    rgb.fill((int(153), int(51), int(0)))
    rgb.write()
    time.sleep_ms(1)

def on_touchpad_O_pressed():
    global i
    time.sleep_ms(500)
    bulb.set_rgb(204, 51, 204)
    oled.DispChar("O键  紫色", 38, 32, 1)
    oled.show()
    rgb.fill((int(102), int(51), int(102)))
    rgb.write()
    time.sleep_ms(1)

def on_touchpad_N_pressed():
    global i
    time.sleep_ms(500)
    bulb.set_rgb(255, 204, 51)
    oled.DispChar("N键  黄色", 38, 32, 1)
    oled.show()
    rgb.fill((int(153), int(102), int(51)))
    rgb.write()
    time.sleep_ms(1)


rgb[1] = (int(51), int(51), int(51))
rgb.write()
time.sleep_ms(1)
music.play('G5:1')
bulb = Bulb(discover_bulbs()[0]["ip"])
time.sleep_ms(500)
bulb.turn_on()
oled.fill(0)
oled.DispChar("触摸键控制RGB灯", 18, 16, 1)
oled.show()[/mw_shl_code]
 楼主| 发表于 2020-6-6 17:04 | 显示全部楼层
mPython X 实验图形编程

16.png
 楼主| 发表于 2020-6-6 17:12 | 显示全部楼层
#MicroPython动手做(17)——掌控板之触摸引脚
#六个触摸键控制的RGB颜色灯(实验视频)

https://v.youku.com/v_show/id_XN ... oneSokuUgc_1.dtitle

17.jpg

 楼主| 发表于 2020-6-14 11:55 | 显示全部楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-27 09:57 , Processed in 0.118271 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表