我真正需要帮助的是,我应该用Python通过风速计计算风速。到目前为止,我唯一的问题是测量每秒发生多少次“点击”。风速计每转一圈,开关就会分合两次。在
下面是我希望代码执行的示例:
每秒10次点击=5英里/小时风速
如果有人能帮我测量每秒的脉冲数,我将不胜感激。在
敬上。在
到目前为止的代码(这将连续打印输出并在按下开关时进行注释):
#!/usr/bin/env python
import uadi2c
import mcp23017
addr2 = 0x21
dio = uadi2c.uadi2c(addr2, debug=False)
portA = mcp23017.GPIOA
portB = mcp23017.GPIOB
dirA = mcp23017.IODIRA
dirB = mcp23017.IODIRB
# chip 1, all output, chip 2 A input, B output
dio.write8(dirA, 0)
dio.write8(dirB, 0x40)
# Now loop reading PA and writing to PB and the terminal
while True:
stuff = dio.readU8(portB)
dio.write8(portA, stuff)
print 'Data read from port B: {0:=08b}'.format(stuff)
目前没有回答
相关问题 更多 >
编程相关推荐