コード例 #1
0
import pyduino
import sys
import time


def usage():
    print """Usage: ./example.py port mode pin
Available modes: 1 - Digital input
                 2 - Digital output
                 3 - PWM
                 4 - Analog input"""


if __name__ == "__main__":
    try:
        arduino = pyduino.Arduino(sys.argv[1])
        mode = int(sys.argv[2])
        pin = int(sys.argv[3])
    except IndexError, ValueError:
        usage()
        sys.exit()
    if mode == 1:
        #Digital input
        arduino.digital_ports[pin >> 3].set_active(1)
        arduino.digital[pin].set_mode(pyduino.DIGITAL_INPUT)
    if mode == 2:
        #Digital output
        arduino.digital_ports[pin >> 3].set_active(1)
        arduino.digital[pin].set_mode(pyduino.DIGITAL_OUTPUT)
        arduino.digital[pin].write(1)  #Turn output high
    if mode == 3:
コード例 #2
0
                d = getPage(self.conf['post'],
                            method="POST",
                            postdata=simplejson.dumps(
                                dict(board=self.conf['boardName'],
                                     pin=pin,
                                     level=int(current))),
                            headers={'Content-Type': 'application/json'})
                d.addErrback(self.reportPostError, pin, current,
                             self.conf['post'])

                self.lastState[pin] = current


if __name__ == '__main__':

    config = {  # to be read from a file
        'arduinoPort': '/dev/ttyUSB0',
        'servePort': 9056,
        'pollFrequency': 20,
        'post': 'http://bang:9069/pinChange',
        'boardName': 'theater',  # gets sent with updates
        'watchPins': [9, 10],  # or 'allInput' (not yet working)
        # todo: need options to preset inputs/outputs at startup
    }

    arduino = pyduino.Arduino(config['arduinoPort'])
    wp = WatchPins(arduino, config)
    task.LoopingCall(wp.poll).start(1 / config['pollFrequency'])
    reactor.listenTCP(config['servePort'], Application(arduino))
    reactor.run()
コード例 #3
0
ファイル: dalek.py プロジェクト: egmeek/Dalek-1
try:
    k = k8055(0)
except IOError:
    print 'could not find K8055 board'
    k = None

#Define arduino Pins

HEAD_POWER = 7
HEAD_DIRECTION = 8
EYE_DIRECTION = 12
EYE_POWER = 11
TEST_PIN = 13

try:
    arduino = pyduino.Arduino("/dev/ttyUSB0")
    set_pin_mode(arduino, 2, 2)
    set_pin_mode(arduino, 3, 2)
    set_pin_mode(arduino, 4, 2)
    set_pin_mode(arduino, 5, 2)
    set_pin_mode(arduino, 6, 2)
    set_pin_mode(arduino, HEAD_POWER, 2)
    set_pin_mode(arduino, HEAD_DIRECTION, 2)
    set_pin_mode(arduino, 9, 2)
    set_pin_mode(arduino, 10, 2)
    set_pin_mode(arduino, EYE_POWER, 2)  #
    set_pin_mode(arduino, EYE_DIRECTION, 2)
    set_pin_mode(
        arduino, TEST_PIN, 2
    )  #Set pin 13 to digital output. Useful for testing, as this pin has a LED on it.
    #TODO: Now set low.
コード例 #4
0
# test
import pyduino
import serial
import time

board = pyduino.Arduino('/dev/ttyACM0')

board.digital[13].set_active(1)
board.digital[13].set_mode(pyduino.DIGITAL_OUTPUT)
board.digital[12].set_active(1)
board.digital[12].set_mode(pyduino.DIGITAL_OUTPUT)
board.digital[2].set_active(1)
board.digital[2].set_mode(pyduino.DIGITAL_INPUT)

# board.digital[13].write(1)
# time.sleep(5)
# board.digital[13].write(0)

# for i in range(2):
#     if i%2 == 0:
#         board.digital[13].write(1)
#     else:
#         board.digital[13].write(0)

#     time.sleep(3)

board.digital[13].write(1)
while True:
    time.sleep(3)
    try:
        value = board.digital[2].read()
コード例 #5
0
def setupSerial():
    global arduino
    arduino = pyduino.Arduino(57600, '*', 0)