コード例 #1
0
ファイル: run.py プロジェクト: dougnd/lightBoard
        def setupPins(pins):
            # build node script to set pin direction:
            mux = 7
            pud = "pulldown"
            script = "var b = require('bonescript');"
            for (p, _) in pins:
                script += " b.pinMode('%s',b.INPUT,%i,'%s','fast');" % (p, mux, pud)
            command = ["node", "-e", script]
            subprocess.call(command, cwd="/usr/local/lib")

            # now use adafruit python lib
            for (p, callback) in pins:
                GPIO.setup(p, GPIO.IN)
                GPIO.add_event_detect(p, GPIO.BOTH)
                GPIO.add_event_callback(p, ButtonHandler(p, callback).handler)
コード例 #2
0
ファイル: encoderRead.py プロジェクト: mdykshorn/mapBot
if __name__ == '__main__':
  try:
    #Initialize node
    rospy.init_node('encoders')
    #Create publisher, to send out a String with the first joint name of every received message as an example.
    pubFR = rospy.Publisher('/py_controller/front_right_wheel/encoder', JointState, queue_size=10)
    pubRR = rospy.Publisher('/py_controller/rear_right_wheel/encoder', JointState, queue_size=10)
    pubFL = rospy.Publisher('/py_controller/front_left_wheel/encoder', JointState, queue_size=10)
    pubRL = rospy.Publisher('/py_controller/rear_left_wheel/encoder', JointState, queue_size=10)
    
	#sets up GPIO channels
    GPIO.setup("P9_23", GPIO.IN)
    GPIO.setup("P9_30", GPIO.IN)
    GPIO.setup("P8_17", GPIO.IN)
    GPIO.setup("P8_26", GPIO.IN)	
	
    GPIO.add_event_detect("P9_23", GPIO.BOTH)
    GPIO.add_event_detect("P9_30", GPIO.BOTH)
    GPIO.add_event_detect("P8_17", GPIO.BOTH)
    GPIO.add_event_detect("P8_26", GPIO.BOTH)

    GPIO.add_event_callback("P9_23", callLeft)
    GPIO.add_event_callback("P9_30", callLeft)
    GPIO.add_event_callback("P8_17", callRight)
    GPIO.add_event_callback("P8_26", callRight)
 

    rospy.spin()
  #If we are interrupted, catch the exception, but do nothing
  except rospy.ROSInterruptException:
    pass
コード例 #3
0
GPIO.setup(led,GPIO.OUT)   

Button = "P9_22"            # UART2_RXD P9_22
GPIO.setup(Button, GPIO.IN)
GPIO.add_event_detect(Button, GPIO.FALLING)


def ButtonFunction(void):
    global alertFlag
    print "ButtonFunction"
    if alertFlag == 0:
        alertFlag = 1
        alertTime = time.time()+60
        GPIO.output(led,GPIO.LOW)
        
GPIO.add_event_callback(Button,ButtonFunction)             # regist the button interrupt function

if __name__=="__main__":
    
    bbg_grove_oled.oled_init()
    bbg_grove_oled.oled_setNormalDisplay()
    bbg_grove_oled.oled_clearDisplay()
    while True:
        # GPIO.output(led,GPIO.HIGH)
        # time.sleep(1)
        # GPIO.output(led,GPIO.LOW)
        # time.sleep(1)
        # print 'led'
        temperature = sensor.read_temperature()
        pressure    = sensor.read_pressure()
        altitude    = sensor.read_altitude()
コード例 #4
0
ファイル: buttons.py プロジェクト: francolargo/BBB-audio
def button8_16 (pin):
    GPIO.output("P8_15", GPIO.LOW)  # SonyTV
    GPIO.output("P8_17", GPIO.HIGH)  # AppleTV
    GPIO.output("P8_19", GPIO.LOW)  # BBB
    GPIO.output("P8_9", GPIO.LOW)  # turn on SPDIF switch
    GPIO.output("P8_7", GPIO.LOW)  # select optical input
    os.system("echo 'AppleTV_in' | nc -q .1 10.0.1.25 8194")
    print "did 8_16 ATV"
    time.sleep(1)
def button8_18 (pin):
    GPIO.output("P8_15", GPIO.LOW)  # SonyTV
    GPIO.output("P8_17", GPIO.LOW)  # AppleTV
    GPIO.output("P8_19", GPIO.HIGH)  # BBB
    GPIO.output("P8_9", GPIO.HIGH)  # Otto off
    os.system("echo 'BBB_in' | nc -q .1 10.0.1.25 8194")
    print "did 8_18 BBB"
    time.sleep(1)
GPIO.add_event_callback("P8_11",button8_11)
GPIO.add_event_callback("P8_12",button8_12)
GPIO.add_event_callback("P8_14",button8_14)
GPIO.add_event_callback("P8_16",button8_16)
GPIO.add_event_callback("P8_18",button8_18)
# main function
def main():
      time.sleep(.5)

if __name__=="__main__":
    while True:
       main()

コード例 #5
0
ファイル: encoder_test.py プロジェクト: mdykshorn/mapBot
#!/usr/bin/python

import Adafruit_BBIO.GPIO as GPIO



def callLeft(data):

	#reads encoder inputs
    channelA = GPIO.input("P9_23")
    channelB = GPIO.input("P9_30")

    print channelA, channelB

	#sets up GPIO channels
GPIO.setup("P9_23", GPIO.IN)
GPIO.setup("P9_30", GPIO.IN)
GPIO.setup("P8_17", GPIO.IN)
GPIO.setup("P8_26", GPIO.IN)	
	
	
#creates an event detect for each of the encoders 
GPIO.add_event_detect("P9_23", GPIO.BOTH)
GPIO.add_event_detect("P9_30", GPIO.BOTH)

while 1:


	#creates a callback if a change happens
	GPIO.add_event_callback("P9_23", callLeft)
	GPIO.add_event_callback("P9_30", callLeft)
コード例 #6
0
estado_porta = GPIO.LOW


# Rotina a ser executada quando uma interrupcao for detectada
def interrupt_callback(pino_botao):
    estado_porta = GPIO.input(pino_porta)
    estado_porta = GPIO.HIGH if estado_porta == GPIO.LOW else GPIO.LOW
    GPIO.output(pino_porta, estado_porta)
    # print ("interrupt")
    return None


# Configuracao do evento de interrupcao do botao
GPIO.add_event_detect(pino_botao, GPIO.FALLING)
GPIO.add_event_callback(pino_botao,
                        callback=interrupt_callback,
                        bouncetime=200)

# Inicializacao da porta serial UART1 da BB
UART.setup("UART1")
ser = serial.Serial(port="/dev/ttyS1", baudrate=9600)
ser.close()
ser.open()
sleep(0.2)

# Conexao ao banco de dados MySQL
db = mysql.connect(user=sql_user,
                   password=sql_pwd,
                   host=sql_host,
                   database=sql_db)
sql_cursor = db.cursor()  # Get a cursor