3386

帖子

0

TA的资源

五彩晶圆(中级)

21
 

10、AB键与玫瑰曲线
玫瑰曲线,按A加1,按B开始

 

玫瑰曲线,基本的意思是:平面内,围绕某一中心点平均分布整数个正弦花瓣的曲线。数学公式是:ρ=a*sin(nθ),a为定长,n为整数(不一定是花瓣数)。

 

由于这个图形不是由直线组成,所以,掌控板上的所有绘图函数均无法使用,只能使用其中的像素点显示功能。命令如下:
        display.pixel(50,0,1)
这个命令中:display.pixel(x, y [,c ]) x , y 为点坐标(x,y)。当如果未给出c,则获取指定像素的颜色值。 如果给出c,则将指定的像素设置为给定的颜色,由于掌控板用的是黑白屏幕,所以用1代表点亮就可以了。

 

#MicroPython动手做(15)——掌控板之AB按键
#玫瑰曲线,按A加1,按B开始,


from mpython import *
import math,time#引入库文件[/align][align=left]
def DrawRoseCurve(a,n):#定义函数,函数名称可以自己命名
    for t in range(0,360):#循环次数,由于是画一圈,所以是360;可以自行设定
        x = math.floor(math.cos(t)*a*math.sin(n*t))#计算x坐标的值,注意:这里需要取整
        y = math.floor(math.sin(t)*a*math.sin(n*t))#计算y坐标的值,并且取整
        display.pixel(x+64,y+32,1) #显示坐标像素点,为什么要+64、+32,哪是因为要把中心坐标(64,32)作为起点
        display.show() #执行[/align][align=left]
# 按键引脚初始化
  
display.fill(0)#清屏
display.show()#清屏执行
  
BTNA = Pin(0, mode=Pin.OPEN_DRAIN,pull=Pin.PULL_UP,value=1)
BTNB = Pin(2, mode=Pin.OPEN_DRAIN,pull=Pin.PULL_UP,value=1)
  
display.DispChar('玫瑰曲线', 38, 0)
display.DispChar('输入花瓣数量,按A加', 0, 17)
display.DispChar('按B开始', 0, 34)
display.show() #执行
  
n1 = 0
jishu = True
Start = False
while True:
    if jishu:
        if BTNA.value() == 0 and  BTNB.value() == 1 :
            display.fill(0)#清屏
            display.show()#清屏执行
            n1 = n1+1
            display.DispChar('数量:%d' % n1, 0, 0)
            display.show()#执行
            time.sleep_ms(400)
        if BTNA.value() == 1 and  BTNB.value() == 0 :
            jishu = False
            Start = True
        if Start:
            if n1%2 == 0:
                n1=n1/2
                display.fill(0)#清屏
                display.show()#清屏执行
                DrawRoseCurve(30,n1)#调用函数
Break

 

 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

22
 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

23
 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

24
 
11、A、B键控制图片转换显示

 

#MicroPython动手做(15)——掌控板之AB按键
#A、B键控制图片转换显示
 
from mpython import *
import music
 
def callback_button_a_pressed():
  oled.fill(0)
  bmp_wZZv = bytearray([0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe3,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x89,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x19,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x39,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x0,0x3f,0xff,0xff,0xff,0xff,0xff,0xfe,0x79,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x1a,0xf,0xff,0xff,0xff,0xff,0xff,0xfe,0xf9,0xff,0xff,0xff,0x3f,0xff,0xff,0x83,0xff,0xe0,0x0,0x0,0x0,0x7f,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xff,0xff,0xf0,0x0,0x1f,0xff,0xff,0xff,0xff,0xff,0xfc,0xf9,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xf9,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x79,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x39,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x99,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe3,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff])
  oled.Bitmap(0, 0, bmp_wZZv, 128, 64, 1)
  oled.show()
 
 
def callback_button_b_pressed():
  oled.fill(0)
  bmp_h61P = bytearray([0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x83,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x99,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x9c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x9e,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x9f,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x9f,0x3f,0xff,0xff,0xff,0xff,0xff,0xf8,0x0,0xf,0xff,0xff,0xff,0xff,0xff,0xff,0x9f,0x3f,0xff,0xff,0xff,0xff,0xff,0xe1,0xff,0x83,0xff,0xff,0xfd,0xff,0xff,0xff,0x9f,0x3f,0xff,0xfc,0x0,0x0,0x0,0x7,0xff,0xc0,0xff,0xff,0xf0,0x7f,0xff,0xff,0x9f,0x3f,0xff,0xfc,0x0,0x0,0x0,0x1f,0xfc,0x0,0x7f,0xff,0xe6,0x0,0x1f,0xff,0x9f,0x3f,0xff,0xf9,0xff,0xcf,0xfe,0x3f,0xf0,0xff,0x1f,0xff,0xc0,0x0,0x7,0xff,0x9f,0x7f,0xf0,0x1,0xff,0xcf,0xfc,0x7f,0xe7,0xff,0x9f,0xc0,0x0,0x0,0x3,0xff,0x9e,0x60,0x0,0x1,0xff,0xcf,0xfc,0xff,0x8f,0xff,0xce,0x3,0xff,0xf0,0x1,0xff,0x9f,0x0,0x0,0x1,0xff,0xcf,0xf9,0xff,0x9f,0xff,0xe0,0x7f,0xff,0xf8,0x0,0xff,0x9f,0x0,0x0,0x1,0xff,0xcf,0xf1,0xff,0x3f,0xff,0xe3,0xff,0xff,0xf8,0x0,0x7f,0x9f,0x0,0x0,0x1,0xff,0xcf,0xf0,0x1e,0xe,0xf,0xcf,0xff,0xff,0xf8,0x0,0x3f,0x9f,0x0,0x0,0x1,0xff,0xff,0xf9,0x6,0x0,0x0,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f,0x9f,0x7f,0xfc,0x1,0xff,0xcf,0xfc,0xff,0xc3,0xff,0xcf,0xc0,0x0,0x0,0x1,0xff,0x9f,0x3f,0xff,0xf9,0xff,0xcf,0xfe,0x7f,0xe3,0xff,0x9f,0xff,0x80,0x0,0x7,0xff,0x9f,0x3f,0xff,0xfd,0xff,0xcf,0xff,0x3f,0xf0,0x7e,0x3f,0xff,0xe7,0x0,0x1f,0xff,0x9f,0x3f,0xff,0xfc,0x0,0x0,0x0,0xf,0xfe,0x0,0x7f,0xff,0xf0,0x3f,0xff,0xff,0x9f,0x3f,0xff,0xfe,0x0,0x0,0x0,0x7,0xff,0xc1,0xff,0xff,0xfc,0xff,0xff,0xff,0x9f,0x7f,0xff,0xff,0xff,0xff,0xff,0xf0,0x58,0x7,0xff,0xff,0xff,0xff,0xff,0xff,0x9e,0x7f,0xff,0xff,0xff,0xff,0xff,0xfc,0x0,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0x9c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x98,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x91,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff])
  oled.Bitmap(0, 0, bmp_h61P, 128, 64, 1)
  oled.show()
 
 
def on_button_a_pressed():
  while True:
    if button_a.value() == 0:
      yield callback_button_a_pressed()
    else:
      yield
 
def on_button_b_pressed():
  while True:
    if button_b.value() == 0:
      yield callback_button_b_pressed()
    else:
      yield
 
func_button_a_pressed = on_button_a_pressed()
func_button_b_pressed = on_button_b_pressed()
while True:
  next(func_button_a_pressed)
  next(func_button_b_pressed)

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

25
 

Mind+ 图形编程

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

26
 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

27
 

11、AB按键切换声光值与三轴数值

 

#MicroPython动手做(15)——掌控板之AB按键
#AB按键切换声光值与三轴数值

 

#MicroPython动手做(15)——掌控板之AB按键
#AB按键切换显示声光值与三轴数值

from mpython import *
import time

def on_button_a_down(_):
    global sensor, switch
    time.sleep_ms(10)
    if button_a.value() == 1: return
    switch = switch + -1
    if switch < 0:
        switch = 2

def on_button_b_down(_):
    global sensor, switch
    time.sleep_ms(10)
    if button_b.value() == 1: return
    switch = switch + 1
    if switch > 2:
        switch = 0

button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)

button_b.irq(trigger=Pin.IRQ_FALLING, handler=on_button_b_down)


switch = 0
oled.fill(0)
oled.DispChar("上一个", 0, 0, 1)
oled.DispChar("下一个", 91, 0, 1)
while True:
    oled.fill_rect(0, 16, 128, 48, 0)
    if switch == 1:
        oled.DispChar((str("声音值:") + str(sound.read())), 30, 28, 1)
    elif switch == 2:
        oled.DispChar((str(" 光线值:") + str(light.read())), 25, 28, 1)
    else:
        oled.DispChar((str("X 轴:") + str(accelerometer.get_x())), 15, 15, 1)
        oled.DispChar((str("Y 轴:") + str(accelerometer.get_y())), 15, 30, 1)
        oled.DispChar((str("Z 轴:") + str(accelerometer.get_z())), 15, 45, 1)
    oled.show()

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

28
 

mPython X 图形编程

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

29
 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

30
 

12、AB按键秒表计时器

 

秒表主要是用来统计秒数的。它有一般有两个按键。A键和B键。

       第一次按下A键时,开始计时。

       第二次按下A键时,暂停计时。

       再按下A键时,继续上一步暂停的计时。

       按下B键,归零。

 

#MicroPython动手做(15)——掌控板之AB按键
#AB按键秒表计时器

 

#MicroPython动手做(15)——掌控板之AB按键
#AB按键秒表计时器from mpython import *

import framebuf

import font.digiface_44

import time

from machine import Timer

def timer1_tick(_):
    global aaa, ttt
    ttt = ttt + 1
    oled.fill(0)
    display_font(font.digiface_44, (''.join([str(x) for x in [ttt // 60, ':', ttt % 60]])), 2, 8, False, 2)
    oled.show()

tim1 = Timer(1)

def on_button_a_down(_):
    global aaa, ttt
    time.sleep_ms(10)
    if button_a.value() == 1: return
    if aaa == 1:
        aaa = 0
        tim1.init(period=1000, mode=Timer.PERIODIC, callback=timer1_tick)
    else:
        aaa = 1
        tim1.deinit()

def on_button_b_down(_):
    global aaa, ttt
    time.sleep_ms(10)
    if button_b.value() == 1: return
    ttt = 0
    oled.fill(0)
    display_font(font.digiface_44, '00:00', 2, 8, False, 2)
    oled.show()
    aaa = 1
    tim1.deinit()

def display_font(_font, _str, _x, _y, _wrap, _z=0):
    _start = _x
    for _c in _str:
        _d = _font.get_ch(_c)
        if _wrap and _x > 128 - _d[2]: _x = _start; _y += _d[1]
        if _c == '1' and _z > 0: oled.fill_rect(_x, _y, _d[2], _d[1], 0)
        oled.blit(framebuf.FrameBuffer(bytearray(_d[0]), _d[2], _d[1],
        framebuf.MONO_HLSB), (_x+int(_d[2]/_z)) if _c=='1' and _z>0 else _x, _y)
        _x += _d[2]

button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)

button_b.irq(trigger=Pin.IRQ_FALLING, handler=on_button_b_down)
oled.fill(0)
display_font(font.digiface_44, '00:00', 2, 8, False, 2)
oled.show()
ttt = 0
aaa = 1

 


 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

31
 

mPython 图形编程

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

32
 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

33
 
本帖最后由 eagler8 于 2020-6-5 12:48 编辑

目录清单
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

 
 
 

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

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/7 下一条

 
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
快速回复 返回顶部 返回列表