欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > 多功能点击器——光遇自动弹琴(源码)

多功能点击器——光遇自动弹琴(源码)

2024/10/26 9:25:07 来源:https://blog.csdn.net/lonelyxxyo/article/details/142853965  浏览:    关键词:多功能点击器——光遇自动弹琴(源码)

今天试了一下用这个多功能点击器自动弹琴,效果非常好

可以看一下演示视频

多功能点击器——自动弹琴(最长的电影)

里面有的调可能因为自己写脚本有出错,凑合听一下,主要还是为了展示用途 。

这个视频主要演示了一下,我写了脚本让它自己按下屏幕某个地方,代码跑起来他就能连贯的弹琴了。如果你需要让它自己做一些自动化工作,写好脚本,同时就能操作很多设备

以下是主要代码

import serial
import time
from beat import play_beat_pattern  # 修改这里,从beat.py导入SERIALOBJ = None#'@'工作模式字典
type2Pins = {1:['0','1'],2:['2','3'],3:['4','5'],4:['6','7'],5:['8','9'],6:['a','b'],7:['c','d'],8:['e','f'],9:['g','h'],10:['i','j'],11:['k','l'],12:['m','n'],13:['o','p'],14:['q','r'],15:['s','t'],16:['u','v']}def sendcmd(t,cmd):sendstr = cmdprint(sendstr)s = t.write(sendstr.encode())t.flush()def touch(p):global SERIALOBJpstr = type2Pins[p][0]sendcmd(SERIALOBJ, pstr)def untouch(p):global SERIALOBJpstr = type2Pins[p][1]sendcmd(SERIALOBJ, pstr)def touchpin(n):if n == 0:n = 10touch(n)time.sleep(0.1)untouch(n)time.sleep(0.1)
def main():global SERIALOBJt = serial.Serial('com3',115200,timeout=1)SERIALOBJ = tif t:print(t.name)               #串口名print(t.port)               #串口号print(t.baudrate)           #波特率print('-'*10)time.sleep(1)sendcmd(t, '@')play_beat_pattern(touch,untouch,touchpin)t.close()else:print('串口不存在')if __name__ == '__main__':main()

在main函数里运行你的脚本内容,这里我是调用了我的一个脚本文件play_beat_pattern(touch,untouch,touchpin)

也就是我的谱子脚本

简谱

对应接口号

说明一下我怎么写的:

"""一小节共8拍,每拍占0.2秒,如果0就是暂停0.2s
比如第十节:
第1拍:同时点击11,5,1
第2拍:0
第3拍:点击10
第4拍:点击10
第5拍:同时点击5,1
第6拍:0
第7拍:0
第8拍:0这一节的代码这样写"""#第10小节#同时11,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(1) touchpin(10)touchpin(10)#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)

以下是我的这首歌脚本,可能有小错误

# beat.py
import timedef play_beat_pattern(touch,untouch,touchpin):
#第一小节touchpin(8)time.sleep(0.2)touchpin(9)time.sleep(0.2)#第二小节#同时11,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)touchpin(10)#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#第三小节#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)touchpin(10)touchpin(11)touchpin(12)time.sleep(0.2)#第四小节#同时11,4,1touch(11)touch(4)touch(1)time.sleep(0.1)            untouch(11)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(10)touchpin(8)#同时4,1touch(4)touch(1)time.sleep(0.1)            untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.6)#第五小节#同时4,1touch(4)touch(1)time.sleep(0.1)            untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.6)touchpin(8)time.sleep(0.2)touchpin(9)time.sleep(0.2)#第六小节#同时11,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)touchpin(10)#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#第七小节#同时5,3touch(5)touch(3)time.sleep(0.1)            untouch(5)untouch(3)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)#953touch(9)touch(5)touch(3)time.sleep(0.1)            untouch(9)untouch(5)untouch(3)time.sleep(0.1)time.sleep(0.2)touchpin(8)time.sleep(0.2)#第八小节#642touch(6)touch(4)touch(2)time.sleep(0.1)            untouch(6)untouch(4)untouch(2)time.sleep(0.1)time.sleep(0.2) touchpin(9)touchpin(9)#同时4,2touch(4)touch(2)time.sleep(0.1)            untouch(4)untouch(2)time.sleep(0.1)time.sleep(0.6)#第九小节#52touch(5)touch(2)time.sleep(0.1)            untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.6)touchpin(8)time.sleep(0.2)touchpin(9)time.sleep(0.2)#第10小节#同时11,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)touchpin(10)#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#第11小节#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)#10.5.1touch(10)touch(5)touch(1)time.sleep(0.1)            untouch(10)untouch(5)untouch(1)time.sleep(0.1)touchpin(11)touchpin(12)time.sleep(0.2)#第12小节#11.4.1touch(11)touch(4)touch(1)time.sleep(0.1)            untouch(11)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)time.sleep(0.2) #841touch(8)touch(4)touch(1)time.sleep(0.1)            untouch(8)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(12)time.sleep(0.2)#第十三小节#11.4.1touch(11)touch(4)touch(1)time.sleep(0.1)            untouch(11)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.6)#第14小节#同时11,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)touchpin(15)#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#第15小节#同时10,5,2touch(10)touch(5)touch(2)time.sleep(0.1)            untouch(10)untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.2) touchpin(9)touchpin(9)time.sleep(2)touchpin(8)touchpin(8)#第16小节#5.1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#5.1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#第17小节touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6) # 第2拍为空,暂停0.2秒;第3拍为空,暂停0.2秒;第4拍为空,暂停0.2秒touch(8)touch(5)touch(1)time.sleep(0.1)            untouch(8)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) # 第6拍为空,暂停0.2秒touchpin(9)time.sleep(0.2) # 第8拍为空,暂停0.2秒#第18小节#同时11,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)touchpin(10)#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#第19小节#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)#10.5.1touch(10)touch(5)touch(1)time.sleep(0.1)            untouch(10)untouch(5)untouch(1)time.sleep(0.1)touchpin(11)touchpin(12)time.sleep(0.2)# 第20节代码touch(11)touch(4)touch(1)time.sleep(0.1)untouch(11)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.2)touch(10)time.sleep(0.2)touchpin(8)time.sleep(0.2)touch(4)touch(1)time.sleep(0.1)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.6)#第21小节touch(4)touch(1)time.sleep(0.1)            untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.6) # 第2拍为空,暂停0.2秒;第3拍为空,暂停0.2秒;第4拍为空,暂停0.2秒touch(8)touch(4)touch(1)time.sleep(0.1)            untouch(8)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.2) # 第6拍为空,暂停0.2秒touch(9)time.sleep(0.1)            untouch(9)time.sleep(0.1)time.sleep(0.2) # 第8拍为空,暂停0.2秒#第22小节#同时11,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)touchpin(10)#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#第23小节touch(5)touch(3)time.sleep(0.1)untouch(5)untouch(3)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)time.sleep(0.2)touch(9)touch(5)touch(3)time.sleep(0.1)untouch(9)untouch(5)untouch(3)time.sleep(0.1)time.sleep(0.2)touchpin(8)time.sleep(0.2)#第24小节#642touch(6)touch(4)touch(2)time.sleep(0.1)            untouch(6)untouch(4)untouch(2)time.sleep(0.1)time.sleep(0.2) touchpin(9)touchpin(9)#同时4,2touch(4)touch(2)time.sleep(0.1)            untouch(4)untouch(2)time.sleep(0.1)time.sleep(0.6)#第25小节touch(9)touch(5)touch(2)time.sleep(0.2)untouch(9)untouch(5)untouch(2)time.sleep(0.2)time.sleep(0.6)touch(8)touch(5)touch(2)time.sleep(0.2)untouch(8)untouch(5)untouch(2)time.sleep(0.2)touchpin(9)time.sleep(0.2)touchpin(8)#第26小节#同时11,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)touchpin(10)#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#第27小节#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)touchpin(10)touchpin(11)touchpin(12)time.sleep(0.2)#第28小节#11.4.1touch(11)touch(4)touch(1)time.sleep(0.1)            untouch(11)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)time.sleep(0.2) #841touch(8)touch(4)touch(1)time.sleep(0.1)            untouch(8)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(15)time.sleep(0.2)#第29小节#4.1   touch(4)touch(1)time.sleep(0.1)            untouch(4)untouch(1)time.sleep(0.1)time.sleep(1.2) touchpin(5)#第30小节#同时11,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)touchpin(15)#同时5,1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.4)touchpin(5)#31touch(10)touch(5)touch(2)time.sleep(0.2)untouch(10)untouch(5)untouch(2)time.sleep(0.2)touchpin(9)time.sleep(0.2)touchpin(15)touch(5)touch(2)time.sleep(0.2)untouch(5)untouch(2)time.sleep(0.2)touchpin(14)time.sleep(0.2)touchpin(15)#32#5.1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#5.1touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)#33touch(5)touch(1)time.sleep(0.1)            untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(10)time.sleep(0.2) #9.5.1touch(9)touch(5)touch(1)time.sleep(0.1)            untouch(9)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) # 第6拍为空,暂停0.2秒touchpin(8)time.sleep(0.2) # 第8拍为空,暂停0.2秒#34#同时6,5,1touch(11)touch(5)touch(1)time.sleep(0.1)            untouch(11)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2) touchpin(9)touchpin(9)#同时4,1touch(4)touch(1)time.sleep(0.1)            untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.6)#35touch(5)touch(2)time.sleep(0.1)untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)time.sleep(0.2)touch(9)touch(5)touch(2)time.sleep(0.1)untouch(9)untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(8)time.sleep(0.2)   #36touch(5)touch(3)time.sleep(0.1)untouch(5)untouch(3)time.sleep(0.1)time.sleep(0.2)touchpin(9)time.sleep(0.2)touchpin(9)touch(5)touch(3)time.sleep(0.1)untouch(5)untouch(3)time.sleep(0.1)time.sleep(0.2)touchpin(8)time.sleep(0.2)touchpin(8)#37touch(6)touch(3)time.sleep(0.1)untouch(6)untouch(3)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)time.sleep(0.2)touch(9)touch(6)touch(3)time.sleep(0.1)untouch(9)untouch(6)untouch(3)time.sleep(0.1)time.sleep(0.2)touchpin(8)time.sleep(0.2)# 38touch(6)touch(4)touch(2)time.sleep(0.1)untouch(6)untouch(4)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(9)touchpin(9)touch(4)touch(2)time.sleep(0.1)untouch(4)untouch(2)time.sleep(0.2)touchpin(8)touchpin(11)# 39     #5,2touch(5)touch(2)time.sleep(0.1)            untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)touchpin(10)touch(5)touch(1)time.sleep(0.1)untouch(5)untouch(1)time.sleep(0.1)touchpin(9)time.sleep(0.2)touchpin(10)#40touch(11)touch(5)touch(1)time.sleep(0.1)   untouch(11)         untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)touchpin(10)touch(11)touch(5)touch(1)time.sleep(0.1)untouch(5)untouch(1)time.sleep(0.1)touchpin(9)time.sleep(0.2)touchpin(10)#41touch(5)touch(1)time.sleep(0.1)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(10)touchpin(11)touch(5)touch(1)time.sleep(0.1)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(10)touchpin(13)#42touch(4)touch(1)time.sleep(0.1)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)touchpin(10)touch(4)touch(1)time.sleep(0.1)untouch(4)untouch(1)time.sleep(0.1)time.sleep(0.2)touchpin(9)time.sleep(0.2)touchpin(9)#43touch(5)touch(2)time.sleep(0.1)untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(9)touchpin(10)touch(5)touch(2)time.sleep(0.1)untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(9)touchpin(12)#44touch(5)touch(3)time.sleep(0.1)untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(9)touchpin(10)touch(5)touch(3)time.sleep(0.1)untouch(5)untouch(3)time.sleep(0.1)time.sleep(0.2)touchpin(7)touchpin(9)#45touch(6)touch(3)time.sleep(0.1)untouch(6)untouch(3)time.sleep(0.1)touchpin(8)time.sleep(0.6)touch(6)touch(3)time.sleep(0.1)untouch(6)untouch(3)time.sleep(0.1)touchpin(5)touchpin(3)#46touch(4)touch(2)time.sleep(0.1)untouch(4)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(8)touchpin(8)touch(4)touch(2)time.sleep(0.1)untouch(4)untouch(2)time.sleep(0.1)touchpin(9)touchpin(11)#47touch(5)touch(2)time.sleep(0.1)untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(10)time.sleep(0.2)touch(9)touch(5)touch(2)time.sleep(0.1)untouch(9)untouch(5)untouch(2)time.sleep(0.1)time.sleep(0.2)touchpin(8)time.sleep(0.2)#48touch(15)touch(5)touch(1)time.sleep(0.1)untouch(15)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)touch(5)touch(1)time.sleep(0.1)untouch(5)untouch(1)time.sleep(0.1)time.sleep(0.6)

代码写好,端口号检查无误,保存运行,点击头就开始自动工作了。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com