掌控板触摸按键的使用

该博客介绍了如何使用掌控板的触摸按键创建两种功能:一是显示触摸按键P和N对应的进度条,二是制作一个抢答器。当触摸按键P或N时,对应进度条会增加,当进度条满时显示获胜者。同时,提供了一个复位按钮O来清零计数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

掌控板触摸按键的使用

当触摸按键P按下时,会在左侧显示%20的进度条,触摸按键按N按下时,会在右侧显示%30的进度条。

在这里插入图片描述

源代码如下:

from mpython import *

import time

myUI = UI(oled)
rgb[0] = (int(0), int(204), int(204))
rgb.write()
time.sleep_ms(1)
oled.fill(0)
oled.DispChar('P', 0, 0, 1)
oled.DispChar('N', 118, 0, 1)
oled.show()
while True:
    if touchpad_p.is_pressed():
        myUI.stripBar(20, 0, 6, 30, 20, 0, 1)
        oled.show()
    if touchpad_n.is_pressed():
        myUI.stripBar(110, 0, 6, 30, 30, 0, 1)
        oled.show()

抢答器的制作

通过触摸按键P和N,当按着使得进度条满了则获胜。

在这里插入图片描述

在这里插入图片描述

源码如下:

from mpython import *

import time

myUI = UI(oled)
p = 0
n = 0
rgb[0] = (int(0), int(204), int(204))
rgb.write()
time.sleep_ms(1)
while True:
    if touchpad_p.is_pressed():
        p = p + 5
    if touchpad_n.is_pressed():
        n = n + 5
    if n >= 99:
        oled.DispChar('N win', 0, 32, 1)
        oled.show()
    if p >= 99:
        oled.DispChar('P win', 0, 32, 1)
        oled.show()
    oled.DispChar('P', 0, 0, 1)
    oled.DispChar('N', 118, 0, 1)
    myUI.stripBar(110, 0, 6, 30, n, 0, 1)
    myUI.stripBar(20, 0, 6, 30, p, 0, 1)
    oled.show()
    if touchpad_o.is_pressed():
        n = 0
        p = 0
        oled.fill(0)
        oled.DispChar('P', 0, 0, 1)
        oled.DispChar('N', 118, 0, 1)
        oled.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值