from ast import Pass
from Phidget22.Phidget import *
from Phidget22.Devices.DigitalInput import *
import time
def onDigitalInput0_StateChange(self, state):
if state == 0:
print("State [0]: " + str(state))
else:
print("the switch is not working")
def onDigitalInput1_StateChange(self, state):
print("State [1]: " + str(state))
def onDigitalInput2_StateChange(self, state):
print("State [2]: " + str(state))
def onDigitalInput3_StateChange(self, state):
print("State [3]: " + str(state))
def onDigitalInput4_StateChange(self, state):
print("State [4]: " + str(state))
def onDigitalInput5_StateChange(self, state):
print("State [5]: " + str(state))
def onDigitalInput6_StateChange(self, state):
print("State [6]: " + str(state))
def onDigitalInput7_StateChange(self, state):
print("State [7]: " + str(state))
def onDigitalInput8_StateChange(self, state):
print("State [8]: " + str(state))
def onDigitalInput9_StateChange(self, state):
print("State [9]: " + str(state))
def main():
digitalInput0 = DigitalInput()
digitalInput1 = DigitalInput()
digitalInput2 = DigitalInput()
digitalInput3 = DigitalInput()
digitalInput4 = DigitalInput()
digitalInput5 = DigitalInput()
digitalInput6 = DigitalInput()
digitalInput7 = DigitalInput()
digitalInput8 = DigitalInput()
digitalInput9 = DigitalInput()
digitalInput0.setDeviceSerialNumber(537128)
digitalInput0.setChannel(0)
digitalInput1.setDeviceSerialNumber(537128)
digitalInput1.setChannel(1)
digitalInput2.setDeviceSerialNumber(537128)
digitalInput2.setChannel(2)
digitalInput3.setDeviceSerialNumber(537128)
digitalInput3.setChannel(3)
digitalInput4.setDeviceSerialNumber(537128)
digitalInput4.setChannel(4)
digitalInput5.setDeviceSerialNumber(537128)
digitalInput5.setChannel(5)
digitalInput6.setDeviceSerialNumber(537128)
digitalInput6.setChannel(6)
digitalInput7.setDeviceSerialNumber(537128)
digitalInput7.setChannel(7)
digitalInput8.setDeviceSerialNumber(537128)
digitalInput8.setChannel(8)
digitalInput9.setDeviceSerialNumber(537128)
digitalInput9.setChannel(9)
digitalInput0.setOnStateChangeHandler(onDigitalInput0_StateChange)
digitalInput1.setOnStateChangeHandler(onDigitalInput1_StateChange)
digitalInput2.setOnStateChangeHandler(onDigitalInput2_StateChange)
digitalInput3.setOnStateChangeHandler(onDigitalInput3_StateChange)
digitalInput4.setOnStateChangeHandler(onDigitalInput4_StateChange)
digitalInput5.setOnStateChangeHandler(onDigitalInput5_StateChange)
digitalInput6.setOnStateChangeHandler(onDigitalInput6_StateChange)
digitalInput7.setOnStateChangeHandler(onDigitalInput7_StateChange)
digitalInput8.setOnStateChangeHandler(onDigitalInput8_StateChange)
digitalInput9.setOnStateChangeHandler(onDigitalInput9_StateChange)
digitalInput0.openWaitForAttachment(5000)
digitalInput1.openWaitForAttachment(5000)
digitalInput2.openWaitForAttachment(5000)
digitalInput3.openWaitForAttachment(5000)
digitalInput4.openWaitForAttachment(5000)
digitalInput5.openWaitForAttachment(5000)
digitalInput6.openWaitForAttachment(5000)
digitalInput7.openWaitForAttachment(5000)
digitalInput8.openWaitForAttachment(5000)
digitalInput9.openWaitForAttachment(5000)
try:
input("Press Enter to Stop\n")
except (Exception, KeyboardInterrupt):
pass
digitalInput0.close()
digitalInput1.close()
digitalInput2.close()
digitalInput3.close()
digitalInput4.close()
digitalInput5.close()
digitalInput6.close()
digitalInput7.close()
digitalInput8.close()
digitalInput9.close()
main()
Asked
Active
Viewed 33 times
-1
Stephen Ostermiller
- 21,408
- 12
- 81
- 104
armando nava
- 1
- 1
-
1Hi Armando, welcome to the site. Take the [tour] if you haven't yet. I've just edited your question to improve the code formatting, but since that requires indenting everything a bit, it's possible I've changed the code in an important way with respect to your issue. Can you make sure it still looks the same as what you are running? Other than something obvious (e.g. the `else` not being indented as much as the `if` above it, or a mix of tabs and spaces, I can't think of anything that would make an `IndentationError` happen in this code. You might just try reindenting it. – Blckknght Jun 02 '22 at 17:05
-
This is how I have it, the else is at the same level as the if, so I don't understand what the error is. – armando nava Jun 02 '22 at 17:20
-
I added my full code – armando nava Jun 02 '22 at 17:26
-
@armandonava Can you add the full error message? – decorator-factory Jun 02 '22 at 23:44
-
Welcome to Stack Overflow! Please take the [tour]. You have mixed tabs and spaces, but they're not visible in the question because Stack Overflow renders tabs as 4 spaces. You can see them in the [Markdown source](/revisions/a6235c18-5689-45f5-b9ef-8fbaf3fe8191/view-source). I closed your question under an existing one that covers this problem and more. BTW, please read [ask] for tips like writing a clear title and making a [mre]. – wjandrea Jun 03 '22 at 00:07