对于一个项目,我使用Raspberry Pi(运行dexter industries modified raspbian)和Brick Pi来运行乐高电机。我用python编写了一个程序,它运行得很好,但是如果压力传感器没有按下,我需要重复运行整个程序。我尝试调用函数sensorValue()(它检测压力传感器是否被按下),同时为True:但是,一旦我做了那些东西变得奇怪。它会继续无限重复,即使我按下传感器,重复的0也会变为1,但它不会调用我需要它运行的下一个功能。
请帮助,这是我第一次真正使用python写任何东西而且我是一个大规模的初学者,所以任何帮助都是非常感激的。
再次感谢
$source = 'C:\Scripts\monthly.csv' # source's fullpath
$target = 'C:\Scripts\template.xlsx' # destination's fullpath
$xl = new-object -com excel.application # creates Excel COM object in powershell
$xl.displayAlerts = $false # don't prompt the user
$wb2 = $xl.workbooks.open($source, $null, $true) # open source, readonly
$wb1 = $xl.workbooks.open($target) # open target
$sh1_wb1 = $wb1.sheets.item('triarqnew') # sheet in destination workbook
$sheetToCopy = $wb2.sheets.item('monthly') # source sheet to copy
# New code
$sheetToCopy.UsedRange.Copy()
$sh1_wb1.Range("A5").PasteSpecial()
$wb2.close($false) # close source workbook w/o saving
$wb1.SaveAs("C:\scripts\Report.xlsx") # close and save destination workbook
$xl.quit()
答案 0 :(得分:1)
试试这个
import BrickPi,time
BrickPiSetup()
BrickPi.MotorEnable[PORT_A] = 1
BrickPi.SensorType[PORT_4] = TYPE_SENSOR_TOUCH
BrickPiSetupSensors()
z = 0
def mainprogram():
print ("running")
while x == 1:
z = z + 1
print ("the plate has been pressed for %s seconds" % z)
time.sleep(1)
while True:
time.sleep(.1)
if BrickPi.Sensor[PORT_4]:
print "program successfully initiatied"
mainprogram()