最右边是编程区域,通过拖动积木模块相互组合,即可完成程序编写,同时会生成对应的python脚本,此时可以直接在仿真区域运行程序,直接观察程序效果。这一点非常的好用,无需实物,且反应非常快。
在连接的情况下,直接点击下载程序,即可将积木对应的固件下载到模块中,下载完成后,模块会主动复位并运行下载的程序。(如果出现下载到98%后停止下载的情况,多下载几次即可)
我这里做了个简单的游戏程序,利用led矩阵和A/B按键完成功能,在最底下的一行存在一个光点1,由AB键控制在最底行左右移动,在最顶行随机生成一个光点2并下落,让光点1接住光点2即可。积木图如下,工程文件放最后。
python脚本如下:
import QHos,QHled,QHaudio,QHinput,QHmathdef pre_run():returndef aftrer_run():returnmonster_1_x = Nonemonster_1_y = Nonehuman_x = Nonestep_time_ms = Nonemonster_1_refresh = Nonedef powerOn():global monster_1_x monster_1_x = 0global monster_1_y monster_1_y = 0global human_x human_x = 0global step_time_ms step_time_ms = 400global monster_1_refresh monster_1_refresh = 0 QHled.set_brightness(3) QHled.show_pic(QHled.HEART) QHaudio.set_volume(2) QHaudio.tone_ring(7) QHos.usleep(100) QHled.clear_led() QHled.show_pixel(human_x,4) while True: if not monster_1_y and not monster_1_refresh: monster_1_refresh= 1 monster_1_x = QHmath.random(0, 4) QHled.change_pixel(monster_1_x,monster_1_y) QHos.usleep(step_time_ms) QHled.cancel_pixel(monster_1_x,monster_1_y) monster_1_y = (monster_1_y if isinstance(monster_1_y, int) else 0) + 1 QHled.change_pixel(monster_1_x,monster_1_y) if monster_1_y == 4: if human_x == monster_1_x: monster_1_y = 0 monster_1_refresh = 0 QHled.change_pixel(human_x,4) else: break QHled.show_pic(QHled.NO) returndef buttonA_func():global human_x QHled.cancel_pixel(human_x,4) human_x = (human_x if isinstance(human_x, int) else 0) - 1if human_x <= 0: human_x = 0 QHled.change_pixel(human_x,4) returndef buttonB_func(): global human_x QHled.cancel_pixel(human_x,4) human_x = (human_x if isinstance(human_x, int) else 0) + 1if human_x >= 4: human_x = 4 QHled.change_pixel(human_x,4) returnQHinput.buttonA_listener(buttonA_func)QHinput.buttonB_listener(buttonB_func)powerOn()
总结:
提示:本文由电子发烧友社区发布,转载请注明以上来源。如需社区合作及入群交流,请添加微信EEFans0806,或者发邮箱liuyong@huaqiu.com。
原文标题:启鸿开发板试用体验:简单使用-接豆子游戏
文章出处:【微信公众号:电子发烧友开源社区】欢迎添加关注!文章转载请注明出处。
全部0条评论
快来发表一下你的评论吧 !