コード例 #1
0
    try:
        val = int(speed)
        t1.throttle(val, hornby.FORWARD)
    except ValueError:
        print

    # needed otherwise the signal will still be transmitted and the loco will continue to move
    if isroot:
        # This calls the function "Motion" when the GPIO pin rises.
        GPIO.add_event_detect(SP, GPIO.RISING, callback=Motion)
    while 1:
        # This causes it to wait for the GPIO pin to trigger
        time.sleep(2)

    # close the connection with a Hornby Elite DCC controller
    hornby.connection_close()
    if isroot:
        GPIO.cleanup()

    print '''
    \t\t\t********************************
    \t\t\t      *****ENDING*****
    \t\t\t********************************
      '''

except KeyboardInterrupt:
    print "Stopping the program"

    t1.throttle(0, hornby.FORWARD)  # stopping the train
    hornby.connection_close()
コード例 #2
0
ファイル: hornby_controller.py プロジェクト: Cavey/py-rail
    try:
      val = int(speed)
      t1.throttle(val,hornby.FORWARD)
    except ValueError:
      print

    # needed otherwise the signal will still be transmitted and the loco will continue to move
    if isroot:
      # This calls the function "Motion" when the GPIO pin rises. 
      GPIO.add_event_detect(SP, GPIO.RISING, callback=Motion)
    while 1:
      # This causes it to wait for the GPIO pin to trigger
      time.sleep(2)

    # close the connection with a Hornby Elite DCC controller 
    hornby.connection_close()
    if isroot:
      GPIO.cleanup()

    print '''
    \t\t\t********************************
    \t\t\t      *****ENDING*****
    \t\t\t********************************
      '''

except KeyboardInterrupt:
    print "Stopping the program"
    
    t1.throttle(0,hornby.FORWARD) # stopping the train
    hornby.connection_close()