123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- import time, sys, signal, atexit
- import pyupm_groveelectromagnet as upmGroveelectromagnet
-
-
-
- myElectromagnet = upmGroveelectromagnet.GroveElectromagnet(2)
-
-
-
-
- def SIGINTHandler(signum, frame):
- raise SystemExit
-
-
-
- def exitHandler():
- print "Exiting"
- myElectromagnet.off()
- sys.exit(0)
-
-
- atexit.register(exitHandler)
- signal.signal(signal.SIGINT, SIGINTHandler)
-
-
- magnetState = False
-
-
- while(1):
- magnetState = not magnetState
- if (magnetState):
- myElectromagnet.on()
- else:
- myElectromagnet.off()
- print "Turning magnet", ("on" if magnetState else "off")
-
- time.sleep(5)
|