SHARE
TWEET

Untitled

a guest Mar 20th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from Plank.ArduinoIO import *
  2.  
  3. class Input:
  4.  
  5.     def __blank( self ):
  6.         pass
  7.  
  8.     pin = -1
  9.     lastState = None
  10.     callbackRising = __blank
  11.     callbackFalling = __blank
  12.  
  13.     def __init__( self, arduinoIO: ArduinoIO, pin ):
  14.         self.arduinoIO = arduinoIO
  15.         self.pin = pin
  16.         arduinoIO.setMode( pin, INPUT )
  17.         self.lastState = arduinoIO.read( pin )
  18.  
  19.     def update( self ):
  20.         state = self.arduinoIO.read( self.pin )
  21.         if state != self.lastState:
  22.  
  23.             self.lastState = state
  24.  
  25.             if state == FALLING:
  26.                 self.callbackFalling( )
  27.             if state == RISING:
  28.                 self.callbackRising( )
  29.  
  30.     def getState( self ):
  31.         return self.arduinoIO.read( self.pin )
  32.  
  33.     def setCallback( self, function, edge ):
  34.         if edge == FALLING:
  35.             self.callbackFalling = function
  36.             self.callbackRising = self.__blank
  37.         if edge == RISING:
  38.             self.callbackFalling = self.__blank
  39.             self.callbackRising = function
  40.         if edge == BOTH:
  41.             self.callbackFalling = function
  42.             self.callbackRising = function
  43.  
  44.     def on( self, edge, function ):
  45.         self.setCallback( function, edge )
  46.  
  47.     def removeCallback( self ):
  48.         self.callbackFalling = self.__blank
  49. self.callbackRising = self.__blank
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top