arduino与python哪个好学_Arduino和Python

我试图通过串行通信控制从Python连接到Arduino的led。我附上了Arduino和python的代码。但是当我在Python中运行代码时,我没有从led得到任何响应,尽管我没有收到任何错误。也许我在语法上犯了些错误?在import serial

import time

arduino=serial.Serial('COM3',250000,timeout=5.0)

m=[]

commands=open('1.txt','r')

lines=commands.readlines()

for line in lines:

m.append(line)

commands.close()

s=0

while s!=len(m):

m[s]=float(m[s])

s+=1

s=0

def delay():

x=0

y=0

while x!=y:

x+=1

while s!=len(m):

c=str(m[s])

if m[s]==1:

arduino.write(b'c')

time.sleep(2)

print('1on')

elif m[s]==-1:

arduino.write(b'c')

time.sleep(2)

print('1off')

delay()

elif m[s]==2:

arduino.write(b'c')

time.sleep(2)

print('2on')

elif m[s]==-2:

arduino.write(b'c')

time.sleep(2)

print('2off')

elif m[s]==3:

arduino.write(b'c')

time.sleep(2)

print('3on')

elif m[s]==-3:

arduino.write(b'c')

time.sleep(2)

print('3off')

s+=1

这是在Arduino中控制Python中的led的代码。Arduino代码如下

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值