Exemplo n.º 1
0
#! /usr/bin/env python3

# PFx Brick example script to retrieve basic information about the
# brick including its identidy and configuration settings.

import hid
import time
from math import sin
from pfxbrick import PFxBrick, PFxAction
from pfxbrick.pfx import *

brick = PFxBrick()
brick.open()
print("Set lights 1, 2, 3, 4 ON")
a = PFxAction().light_on([1, 2, 3, 4])
brick.test_action(a)
time.sleep(2)

for x in range(100):
    b = int(sin(6.28 * x * 0.1) * 127 + 128)
    brick.test_action(PFxAction().set_brightness([1, 2, 3, 4], b))
    time.sleep(0.050)

print("Set lights 1, 2, 3, 4 OFF")
a = PFxAction().light_off([1, 2, 3, 4])
brick.test_action(a)
time.sleep(2)

print("Set strobe lights 1, 4 ON")
a = PFxAction().light_fx(
    [1, 4], EVT_LIGHTFX_STROBE_P,
Exemplo n.º 2
0
# PFx Brick example script to demonstrate multiple scripted actions

import hid
import time
import random
from pfxbrick import PFxBrick, PFxAction
from pfxbrick.pfx import *

brick = PFxBrick()
brick.open()

audiofile = 2
max_speed = 100

# start looped audio playback and set volume
brick.test_action(PFxAction().repeat_audio_file(audiofile))
brick.test_action(PFxAction().set_volume(75))

# ramp up the motor speed gradually to max_speed
for x in range(max_speed):
    brick.test_action(PFxAction().set_motor_speed([1], x))
    # show a random light pattern
    y = random.randint(1,8)
    brick.test_action(PFxAction().light_toggle([y]))
    time.sleep(0.1)

# ramp down the motor speed gradually to 0%

for x in range(max_speed):
    brick.test_action(PFxAction().set_motor_speed([1], max_speed-x-1))
    # show a random light pattern
Exemplo n.º 3
0
#! /usr/bin/env python3

# PFx Brick example script to demonstrate motor control

import hid
import time
from pfxbrick import PFxBrick, PFxAction
from pfxbrick.pfx import *

brick = PFxBrick()
brick.open()

print("Motor channel A forward 50% speed")
a = PFxAction().set_motor_speed([1], 50)
brick.test_action(a)
print("Waiting 3 seconds...")
time.sleep(3)

print("Stop motor A")
a = PFxAction().stop_motor([1])
brick.test_action(a)
time.sleep(1)

print("Motor channel A reverse 33% speed for 2 sec self-timed")
a = PFxAction().set_motor_speed([1], -33, 2)
brick.test_action(a)

brick.close()