コード例 #1
0
 def test_find(self):
     """ Tests auto-connection/board detection. """
     raw_input(
         'Plug in Arduino board w/LED at pin 13, reset, then press enter')
     from Arduino import Arduino
     board = None
     try:
         # This will trigger automatic port resolution.
         board = Arduino(9600)
     finally:
         if board:
             board.close()
コード例 #2
0
 def test_find(self):
     """ Tests auto-connection/board detection. """
     input(
         'Plug in Arduino board w/LED at pin 13, reset, then press enter')
     from Arduino import Arduino
     board = None
     try:
         # This will trigger automatic port resolution.
         board = Arduino(9600)
     finally:
         if board:
             board.close()
コード例 #3
0
 def test_open(self):
     """ Tests connecting to an explicit port. """
     port = None
     while not port:
         port = raw_input(
             'Plug in Arduino board w/LED at pin 13, reset.\n'\
             'Enter the port where the Arduino is connected, then press enter:')
         if not port:
             print 'You must enter a port.'
     from Arduino import Arduino
     board = None
     try:
         board = Arduino(9600, port=port)
     finally:
         if board:
             board.close()
コード例 #4
0
 def test_open(self):
     """ Tests connecting to an explicit port. """
     port = None
     while not port:
         port = input(
             'Plug in Arduino board w/LED at pin 13, reset.\n'\
             'Enter the port where the Arduino is connected, then press enter:')
         if not port:
             print('You must enter a port.')
     from Arduino import Arduino
     board = None
     try:
         board = Arduino(9600, port=port)
     finally:
         if board:
             board.close()
コード例 #5
0
        #print(msg)
        msgList = str(msg).split(' ')
        if msgList[0] == 'note_on':
            channel = msgList[1][8:]
            note = msgList[2][5:]
            velocity = msgList[3][9:]
            delay = msgList[4][5:]
            playList.append([channel, note, velocity])
            timeDelay.append(delay)

pygame.init()
pygame.mixer_music.load('004.MID')  # load midi file with pygame.mixer_music, ready to play
pygame.mixer_music.play()     #play midi music

while True:
    try:
        print("stageA")
        board.digitalWrite(13,"HIGH")
        board.Servos.write(4, 0)
        time.sleep(1)
        print("stageB")
        board.Servos.write(4, 90)
        board.digitalWrite(13,"LOW")
        time.sleep(1)

    except KeyboardInterrupt:
        print("exit...")
        board.close()
        pygame.mixer_music.stop()

        
コード例 #6
0
def led_on():
    board.digitalWrite(12, 'HIGH')


def led_off():
    board.digitalWrite(12, 'LOW')


while board.pinMode(12, "OUTPUT") != 1:  #LED接12pin
    board.pinMode(12, "OUTPUT")

while 1:
    IRflag = board.IRstart(11)  #红外接收传感器只能连接到11脚

    if IRflag == 1:

        print("Start")
        break

while 1:
    IRvalue = board.IRrecv()
    if IRvalue == "FF30CF":  #按钮1
        print(IRvalue)
        led_on()
    elif IRvalue == "FF6897":  #按钮0
        print(IRvalue)
        led_off()

board.close()
コード例 #7
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 21 18:00:15 2019

Script to turn LED on

@author: mkals
"""

from Arduino import Arduino

board = Arduino()  # find and connect microcontroller
print('Connected')  # confirms the microcontroller has been found

board.pinMode(3, 'OUTPUT')  # configure pin D3 to be an output pin
board.digitalWrite(3, 'HIGH')  # make LED light up

board.close()  # close the connection to the board
コード例 #8
0
ファイル: photobooth.py プロジェクト: helorem/photobooth
if __name__ == "__main__":
    Strings.get_instance().load(ResourceManager.get(
        Config.get("strings_file")))
    camera = Camera()
    arduino = Arduino()
    Screen.get_instance().init(camera)
    try:
        camera.start()
        arduino.start()
        try:
            arduino.register_callback(Arduino.BUTTON_3, quit,
                                      Config.get("halt_delay"))

            sm = SceneManager().get_instance()
            sm.add_scene(WelcomeScene(arduino))
            sm.add_scene(SettingsScene(arduino))
            sm.add_scene(SelectModeScene(arduino))
            sm.add_scene(SnapScene(arduino, camera))
            sm.add_scene(SnapPhotomatonScene())
            sm.add_scene(SnapSpecialScene(arduino, camera))
            sm.add_scene(SelectEffectScene(arduino))
            sm.set_main_scene("welcome")
            sm.start()
        finally:
            arduino.stop()
            arduino.close()
            camera.stop()
    finally:
        Screen.get_instance().close()
コード例 #9
0
@author: mkals
"""

from Arduino import Arduino
import time

PIN = 7  # pin where temperature sensor is connected

# connect to Arduino
board = Arduino()
print('Connected')

try:
    while True:
        # make distance measurement

        data = board.dht(PIN)

        [humidity, temperature, heatIndex] = data

        reply = "Humidity = " + str(humidity) + " % \t"
        reply += "Temperature = " + str(temperature) + " ˙C \t"
        reply += "Heat Index = " + str(heatIndex) + " ˙C"

        print(reply)

        time.sleep(1)  # delay to keep UART bus for getting overloaded

except:
    board.close()  # close serial connection
コード例 #10
0
                    newline='')  # prepare for writing to file

# Write data-field titles to file
writer.writerow(['Counter', 'Time (s)', 'Distance (cm)'])

counter = 0  # to count how many data-points we have collected
startTime = time.time()  # capture current time as datum

try:
    while True:
        counter = counter + 1  # increment counter

        # make distance measurement without averaging
        pulseTime = board.pulseIn_set(PIN_SENSE, 'HIGH')
        distance = pulseTime * 0.034 / 2
        # in cm

        # write list of data to file
        writer.writerow([counter, time.time() - startTime, distance])

        # print to console every 10 itterations. % is modulo operator
        if counter % 10 == 0:
            print(distance)

        time.sleep(0.01)  # delay to keep UART bus for getting overloaded

# press ctrl+c while the console is active to terminate the program
except KeyboardInterrupt:
    board.close()  # close board connection
    f.close()  # close file gracefully when program is terminated
コード例 #11
0
import time
from Arduino import Arduino

port = 'COM6'
ard = Arduino(port)

ard.pinMode(2, ard.OUTPUT)
ard.pinMode(3, ard.INPUT)
ard.pinMode(4, ard.OUTPUT)
for i in range(10):
    print(ard.analogRead(0))
    time.sleep(1)
ard.analogWrite(5, 100)  # utiliser une sortie PWM pour cela
for i in range(10):
    ard.digitalWrite(2, ard.HIGH)
    time.sleep(1)
    ard.digitalWrite(2, ard.LOW)
    time.sleep(1)
    print(ard.digitalRead(3))
ard.close()