def __init__(self, pin, value=90, min=0, max=180): self.pin = pin self.value = value self.min = min self.max = max pz.setOutputConfig(self.pin, 2) pz.setOutput(self.pin, self.value)
def __init__(self): pz.init() self._pan = 0 self._tilt = 1 pz.setOutputConfig(self._pan, 2) pz.setOutputConfig(self._tilt, 2) self.tilt(90) self.pan(90)
def __init__(self, intensity=100, pin=0): ''' Itensity (0 - 100) of LED brightness and its pin on Picon Zero can be specified. ''' pz_state_controller.ensure_piconzero_is_initialized() self.intensity = int(intensity) self.pin = pin if self.intensity == 100: pz.setOutputConfig(self.pin, 0) else: pz.setOutputConfig(self.pin, 1)
def __init__(self): pz.init() # 1= 2 place, 1 = PWM output channel pz.setOutputConfig(1, 1) # 2= 3 place, 1 = PWM output channel pz.setOutputConfig(2, 1) # Set initial state as off pz.setOutput(1, 0) pz.setOutput(2, 0) # Create a lock to syncronize access to hardware from multiple threads. self._lock = threading.Lock()
def init(): print("Simple obstacle avoider") print("Press Ctrl-C to end") print() pz.init() pz.setOutputConfig(5, 3) # set output 5 to WS2812 rev = pz.getRevision() print(rev[0], rev[1]) hcsr04.init()
def neoPixelLight(direction): # setup neopixel output pz.setOutputConfig(5, 3) if direction == "forward": pz.setAllPixels(255, 0, 0) elif direction == "backward": pz.setAllPixels(255, 255, 0) elif direction == "left": pz.setAllPixels(127, 127, 255) elif direction == "right": pz.setAllPixels(255, 255, 255) elif direction == "off": pz.setAllPixels(0, 0, 0)
def initialise(): # Setup pz.init() pz.setOutputConfig(0, 2) # set output 0 to Servo pz.setOutputConfig(1, 1) # set output 1 to PWM pz.setOutputConfig(2, 1) # set output 2 to PWM pz.setOutputConfig(3, 1) # set output 3 to PWM pz.setInputConfig(0, 0) # set input 1 to digital # Setup Action queues global qLED qLED = Queue(maxsize=0) global qServo qServo = Queue(maxsize=0) workerLED = Thread(target=processq, args=(qLED, )) workerLED.setDaemon(True) workerLED.start() workerServo = Thread(target=processq, args=(qServo, )) workerServo.setDaemon(True) workerServo.start() # Initialise dropbox global dbx dbx = dropbox.Dropbox(get_dropboxkey())
def setup(): print('initializing servGrap') # read channel from config channel = int(IniReader.read('pins', 'SERVO_CHANNEL')) # Set output mode to Servo pz.setOutputConfig(0, channel) pz.setOutputConfig(1, channel) pz.setOutputConfig(2, channel) print('resetting servo to DOWN position , waiting 1 second ...') ServGrap.hook(ServGrap.DOWN) time.sleep(1) print('servGrap initialised and ready')
def initPZ(): pz.init() # Set output mode to Servo pz.setOutputConfig(pan, 2) pz.setOutputConfig(tilt, 2) # set output 5 to WS2812 pz.setOutputConfig(pixel, 3) hcsr04.init() # Centre all servos panVal = 90 tiltVal = 90 pz.setOutput(pan, panVal) pz.setOutput(tilt, tiltVal)
speed = 60 print("Tests the servos by using the arrow keys to control") print("Press <space> key to centre") print("Press Ctrl-C to end") print() # Define which pins are the servos pan = 0 tilt = 1 grip = 2 pz.init() # Set output mode to Servo pz.setOutputConfig(pan, 2) pz.setOutputConfig(tilt, 2) pz.setOutputConfig(grip, 2) # Centre all servos panVal = 90 tiltVal = 90 gripVal = 90 pz.setOutput(pan, panVal) pz.setOutput(tilt, tiltVal) pz.setOutput(grip, gripVal) # main loop try: while True: keyp = readkey()
import piconzero as pz, time pz.setInputConfig(0, 1) # set input 0 to Analog pz.setOutputConfig(0, 1) # set output 0 to PWM pz.setOutputConfig(2, 2) # set output 2 to Servo pz.setOutputConfig(5, 3) # set output 5 to WS2812 while True: ana0 = pz.readInput(0) pz.setOutput(0, ana0/10) pz.setPixel(0,0,0,ana0/4) pz.setOutput(2, int(ana0/7)) time.sleep(0.1) # this makes 11 active lines, but can be removed
import piconzero as pz, time from libsoc import gpio from libsoc import GPIO from time import sleep def sensor_activated(): gpio_in = gpio.GPIO(GPIO.gpio_id("GPIO-A"), gpio.DIRECTION_INPUT) with gpio.request_gpios(gpio_in): in_val = gpio_in.is_high() return in_val pz.init() pz.setOutputConfig(0, 2) # set output 0 to Servo pz.setOutputConfig(1, 1) # set output 1 to PWM pz.setOutputConfig(2, 1) # set output 2 to PWM pz.setOutputConfig(3, 1) # set output 3 to PWM rev = pz.getRevision() print rev[0], rev[1] try: while True: while not sensor_activated(): sleep(1) for x in range(0, 50): pz.setOutput(1, x) time.sleep(0.04) pz.setOutput(1, 0) sleep(3)
import time import sys import random import colorsys import threading # Initiate motor controller pz.init() animation = None # Control Setup left_stick = 0.0 right_stick = 0.0 # ACTIVATE BLINKY LIGHTS pz.setOutputConfig(5, 3) pz.setBrightness(255) class Animation(threading.Thread): daemon = True def __init__(self): super(Animation, self).__init__() self.style = None def run(self, target): while self.running: self.next_color() time.sleep(self.sleeptime)
#set the pi we are workign with (default to local) pi = pigpio.pi() #let test this, subject to change, useful for adjusting RPM. speed = 25 #reference point to poll for changes futureTick = 20001 #pin row on piconzero turnServo = 0 pz.init() # Set output mode to Servo and frequency for servo pz.setOutputConfig(turnServo, 2) pi.set_PWM_frequency(18, 240) # Set frequency for Motor 50Hz * 25 speed = 1250RPM #20.83_ rotations per second pi.set_PWM_frequency(4, 50) #max right panMax = 180 #center pos panCenter = 90 #max left panMin = 0 #initially center panned, using this for PWM smooth transitions panValue = 90
import piconzero as pz, time pz.init() pz.setOutputConfig(5, 3) # set output 5 to WS2812 pz.setBrightness(15) delay = 0.1 colour = [0,255,125] # colour format of LEDs 0 to 7 is G R B # Set rear light to Red for posistion in range(4, 8, 1): pz.setPixel(posistion, 0, 255, 0) try: while True: for posistion in range(0,4,1): pz.setPixel(posistion, colour[0], colour[1], colour[2]) time.sleep(delay) for off in range(0, 4, 1): pz.setPixel(off, 0,0,0) time.sleep(delay) for posistion in range(2, 0, -1): pz.setPixel(posistion, colour[0], colour[1], colour[2]) time.sleep(delay) for off in range(0, 4, 1): pz.setPixel(off, 0, 0, 0) time.sleep(delay) except KeyboardInterrupt: print ('finished') finally: pz.cleanup()
import piconzero as pz print("Halloween animation using servos") print("Press Ctrl-C to end") print pz.init() number_servos = 5 start_angle = 45 stop_angle = 135 delay_time = 0.3 # Define which pins are the servos and set their output and centre them for s in range(number_servos): pz.setOutputConfig(s, 2) pz.setOutput(s, start_angle) sleep(delay_time) # main loop try: # while True: for i in range(5): for servo in range(number_servos): pz.setOutput(servo, stop_angle) sleep(delay_time) pz.setOutput(servo, start_angle) sleep(delay_time) except KeyboardInterrupt: print
print("Test the servos by using the arrow keys to control") print("Press <space> key to centre") print("Press Ctrl-C to end") print() # Define which pins (GPIO) are the servos rot = 0 # bottom servo, responsible for rotation in the ground plane. Left/Right. tilt = 1 # left servo, moves the claw Forward/Backward lift = 2 # right servo, moves the claw Up/Down grip = 3 # head servo, Opens/Closes the grip pz.init() # Set output mode to Servo pz.setOutputConfig(rot, 2) pz.setOutputConfig(tilt, 2) pz.setOutputConfig(lift, 2) pz.setOutputConfig(grip, 2) # Operational angles of servos (between 0 and 180) limited by device geometry tiltMax = 115 tiltMin = 55 rotMin = 0 rotMax = 180 liftMax = 75 liftMin = 0 gripMin = 0 gripMax = 110 # Initial position of all servos at the beginning of operation
#! /usr/bin/env python #testLedNumbers.py # Testing McRoboFace led positions. # requires picon zero hardware plus software library import piconzero as pz, time pz.init() pz.setOutputConfig(5, 3) # set output 5 to WS2812 (code 3) try: while True: for i in xrange(0, 17): pz.setPixel(i, 0, 0, 255) time.sleep(0.5) pz.setAllPixels(0, 0, 0) time.sleep(0.5) except KeyboardInterrupt: print finally: pz.cleanup() #reset picon zero board
speed = 60 print "Tests the servos by using the arrow keys to control" print "Press <space> key to centre" print "Press Ctrl-C to end" print # Define which pins are the servos pan = 0 tilt = 1 grip = 2 pz.init() # Set output mode to Servo pz.setOutputConfig(pan, 2) pz.setOutputConfig(tilt, 2) pz.setOutputConfig(grip, 2) # Centre all servos panVal = 90 tiltVal = 90 gripVal = 90 pz.setOutput (pan, panVal) pz.setOutput (tilt, tiltVal) pz.setOutput (grip, gripVal) # main loop try: while True: keyp = readkey()
from __future__ import absolute_import import piconzero as pz, time pz.setInputConfig(0, 1) # set input 0 to Analog pz.setOutputConfig(0, 1) # set output 0 to PWM pz.setOutputConfig(2, 2) # set output 2 to Servo pz.setOutputConfig(5, 3) # set output 5 to WS2812 while True: ana0 = pz.readInput(0) pz.setOutput(0, ana0/10) pz.setPixel(0,0,0,ana0/4) pz.setOutput(2, int(ana0/7)) time.sleep(0.1) # this makes 11 active lines, but can be removed
#init servo outputs #ch0 servoPort0 = 0 #ch1 servoPort1 = 1 #ch2 servoPort2 = 2 #define input ports analogPort0 = 0 #input port 0 analogPort1 = 1 #input port 1 # Set output mode pz.setOutputConfig(servoPort0, 2) #set to output Servo (0 - 180) #pz.setOutputConfig(servoPort0, 1) # set output 0 to PWM (100) # Set input mode pz.setInputConfig(analogPort0, 1) # set input 0 to Analog def motor(servoPort, speed): #activate servo hat servo motor pz.setOutput(servoPort, speed) class Encoder(threading.Thread): 'Class for Analog encoder on continous rotation servo motors' def __init__(self, servo_port, analog_port, threshold): threading.Thread.__init__(self)
self.epoll = select.epoll() self.fdmap = {} def register(self, obj, flags): fd = obj.fileno() self.epoll.register(fd, flags) self.fdmap[fd] = obj def unregister(self, obj): fd = obj.fileno() del self.fdmap[fd] self.epoll.unregister(fd) def poll(self): evt = self.epoll.poll() for fd, flags in evt: yield self.fdmap[fd], flags if __name__ == "__main__": pollster = EPoll() pollster.register(Server(("", 54321), pollster), select.EPOLLIN) pz.init() pz.setOutputConfig(5, 3) # set output 5 to WS2812 hcsr04.init() while True: evt = pollster.poll() for obj, flags in evt: readwrite(obj, flags)
# current sensor state leftState=0 rightState=0 # running total of change of state leftTotal=0 rightTotal=0 # init all hardware pz.init() # Set output mode to Servo pz.setOutputConfig(pan, 2) pz.setOutputConfig(tilt, 2) pz.setOutputConfig(cam, 2) pz.setInputConfig(irSen, 1) # set input 0 to Analog pz.setInputConfig(leftCounter, 0) # set input 0 to Analog pz.setInputConfig(rightCounter, 0) # set input 0 to Analog # Centre positions for all servos panVal = 90 tiltVal = 90 camVal = 90 pz.setOutput (pan, panVal) pz.setOutput (tilt, tiltVal)