示例#1
0
async def _comain(mc):

    print("Press user switch to start.")
    userSwitch = Switch()
    while not userSwitch.value():
        await sleep_ms(200)

    print("Starting")
    await sleep_ms(1000)

    try:
        print("Go!")
        mc.goForwards()
        await sleep_ms(5000)
        mc.stop()
        await sleep_ms(1000)
        mc.goBackwards()
        await sleep_ms(5000)
        mc.stop()
        await sleep_ms(1000)
        mc.turnRight()
        await sleep_ms(2000)
        mc.stop()
        await sleep_ms(1000)
        mc.turnLeft()
        await sleep_ms(2000)

    finally:
        print("Stopping")
        mc.stop()
async def serve(esp):

    esp.initServer(EchoConnection)
    #esp.initServer(LedToggleConnection)
    print("Waiting for connections...")

    sw = Switch()
    while not sw.value():
        await ua_sleep_ms(200)

    esp.stopServer()
    print("Server stopped.")
示例#3
0
async def mainTask(mc, count):

    print("Press user switch to start.")
    userSwitch = Switch()
    while not userSwitch.value():
        await sleep_ms(200)

    print("Starting")
    await sleep_ms(1000)

    await mc.goForwardsTo(count)
    await sleep_ms(1000)
    await mc.goBackwardsTo(count)
示例#4
0
async def mainTask(motion):
    
    print("Press user switch to start.")
    userSwitch = Switch()
    while not userSwitch.value():
        await sleep_ms(200)
    
    print("Starting")
    await sleep_ms(1000)
    
    print("turning counter clockwise")
    await motion.turn(radians(-30))
    await sleep_ms(1000)
    print("turning clockwise")
    await motion.turn(radians(60))
    print("finished")
示例#5
0
async def mainTask(mc):

    print("Press user switch to start.")
    userSwitch = Switch()
    while not userSwitch.value():
        await sleep_ms(200)

    print("Starting")
    await sleep_ms(1000)

    await mc.turnTo(radians(30))
    await sleep_ms(1000)
    await mc.turnTo(0)
    await sleep_ms(1000)
    await mc.turnTo(radians(330))
    await sleep_ms(1000)
    await mc.turnTo(0)
    await sleep_ms(1000)
    await mc.turn(radians(15))
    await sleep_ms(1000)
    await mc.turn(radians(15))
    await sleep_ms(1000)
    await mc.turn(radians(-30))
示例#6
0
------------------------------------------------------------------------

History:
  19 june 2020 - Pierson F. - initial code
"""
import pyb
from pyb import LED, Switch
import time

orange = LED(3)
bleu = LED(4)
sw = Switch()

# pyb.freq(48000000)

# boucle d'affichage
while (1):
    for i in range(0, 255):
        while sw.value() == True:
            time.sleep_ms(1000)
        orange.intensity(i)
        bleu.intensity(255 - i)
        time.sleep_ms(5)
    for i in range(0, 255):
        while sw.value() == True:
            time.sleep_ms(1000)
        orange.intensity(255 - i)
        bleu.intensity(i)
        time.sleep_ms(5)
示例#7
0
'''
from pyb import Switch
from ulab import numerical
from time import sleep
import mlx90615 as mlx

MIN_TEMP_ACCEPT = 3400  # (34.00 C)
MAX_TEMP_ACCEPT = 4200  # (42.00 C)
TIME_MS_BETWEEN_TEMP_MEASUREMENTS = 0.5  # 500 ms = 0.500 s
NUM_TEMP_MEASURE = 8
TIME_MS_AFTER_TEMP_MEASUREMENTS = 7  # 7000 ms = 7.000 s
# start's software

flag_exit = False
sw = Switch()
sw.value()  # returns True or False

while True:
    print('\nEsperando proximidade ...', end='')
    while (not flag_exit):
        if sw.value(
        ) == True:  # estímulo que indica a presença de uma pessoa/objeto perto do protótipo
            pyb.LED(2).on()
            print('\nOi, eu sou o uPyBodyTempIR-PYBD_v0.4\n')
            print('Fique a 3cm da tela.')
            sleep(2)
            print('Fique Parado!\n')
            break
        else:
            pyb.LED(2).off()
            print('.', end='')
示例#8
0
sensor = Ultrasonic(Pin.board.X3, Pin.board.X4)

# Create variable which detects the USR button being pressed.
switch = Switch()

# Read configuration values from our json config file
config_file = open('config.json', 'r')
config = ujson.loads(config_file.read())
print("Config file read")
print("Pump controller version: {}".format(config['pump_controller_version']))
print("Pump sensor read time period is: {}".format(
    config['ultrasonic_time_period']))
time_period = config['ultrasonic_time_period']

print("***Starting pump controller! ****")
print("USR switch value is: {}".format(switch.value()))
counter = 1

while not switch.value():
    led2.toggle()
    print('*** Pump controller active! ***')

    if counter >= time_period:

        try:
            dist = sensor.distance_in_cm()
            print("Dist = {}".format(dist))
        except MeasurementTimeout as e:
            print("{}".format(e))
        counter = 1
示例#9
0
from time import sleep
from urandom import choice, randint

# Untrasonic
TRIGGER_PIN = "S18"
ECHO_PIN = "S16"
# Zumo
RIGHT_SERVO = 4  # S10
LEFT_SERVO = 3  # S8

sr04 = Ultrasonic(Pin(TRIGGER_PIN), Pin(ECHO_PIN))
zumo = ServoZumo(left_servo=LEFT_SERVO, right_servo=RIGHT_SERVO)
sw = Switch()

# Wait user A to be pressed
while not sw.value():
    sleep(0.100)

# wait 10 secondes before start
for i in range(9):
    LED(1).on()
    sleep(0.100)
    LED(1).off()
    sleep(1)
# Final indicator
LED(1).on()
sleep(1)
LED(1).off()

try:
    while True:
示例#10
0
led = LED(1)  # 1=red, 2=green, 3=yellow, 4=blue
led.toggle()
led.on()
led.off()

# LEDs 3 and 4 support PWM intensity (0-255)
LED(4).intensity()  # get intensity
LED(4).intensity(128)  # set intensity to half

# Internal switch
# See pyb.Switch.

from pyb import Switch

sw = Switch()
sw.value()  # returns True or False
sw.callback(lambda: pyb.LED(1).toggle())

# Pins and GPIO
# See pyb.Pin.

from pyb import Pin

p_out = Pin("X1", Pin.OUT_PP)
p_out.high()
p_out.low()

p_in = Pin("X2", Pin.IN, Pin.PULL_UP)
p_in.value()  # get value, 0 or 1

# Servo control
示例#11
0
    SPAN_DIST = MAX_DIST - MIN_DIST

    MIN_FREQ = 110.0
    MAX_FREQ = 880.0
    SPAN_FREQ = MAX_FREQ - MIN_FREQ

    meter = Ultrasound(Pin.board.D2, Pin.board.D4)
    buzzer = Buzzer(Pin.board.D12, 3, 1)

    switch = Switch()

    try:

        # Wait for switch button press the first time
        print("Press switch button to start")
        while not switch.value():
            sleep_ms(CHECK_TIME)

        # Wait for switch button release
        while switch.value():
            sleep_ms(CHECK_TIME)

        # Wait for swith button press to finish
        print("Press switch button to finish")
        while not switch.value():
            dist = meter.read()
            if MIN_DIST <= dist <= MAX_DIST:
                freq = MAX_FREQ - ((dist - MIN_DIST) * SPAN_FREQ / SPAN_DIST)
                buzzer.startBuzz(freq)
            else:
                buzzer.stopBuzz()
示例#12
0
	return int(x) if x < 255 else 255

def gamma_color( color ):
	""" Apply the Gamma correction to a tuple of rgb color.
		Eyes does not sense the color range in a linear way """
	return gamma_255(color[0]), gamma_255(color[1]), gamma_255(color[2])

# Started and ready for operation
sleep( 0.300 )
np.fill( (128,0,0) ) # GRB Started
np.write()
sleep( 0.500 )
np.fill( (0,0,0) ) # switch off
np.write()

# Main loop reading color and printing it every second.
catch_color = False
while True:
	if switch.value():
		catch_color = not( catch_color )
		led.value( catch_color ) # Light the Acquire LED
		sleep( 0.5 )

	if catch_color:
		# Read the color at the sensor
		rgb = color.color_rgb_bytes    # color_rgb_bytes
		np.fill( (rgb[1],rgb[0],rgb[2]) ) # Give it as grb for triple ring
		np.write()
		# Delay for a second and repeat.
	sleep(0.100)