def neo_pixel_control(self, number_of_pixels, pixel_position, red, green, blue): """ This is the neopixel handler Typical command: to_hardware {'number_of_pixels': 8, 'command': 'set_pixel', 'green': 128, 'red': 121, 'pixel_position': 4, 'blue': 137} :param number_of_pixels: pixels on ring or strip :param pixel_position: pixel number to control - zero is the first :param red: color value :param green: color value :param blue: color value """ crickit.init_neopixel(number_of_pixels) crickit.neopixel.fill(0) # Assign to a variable to get a short name and to save time. np = crickit.neopixel np[pixel_position] = (red, green, blue)
parrot_0 = (255, 75, 0) parrot_1 = (255, 200, 0) parrot_2 = (90, 255, 90) parrot_3 = (0, 255, 255) parrot_4 = (0, 160, 255) parrot_5 = (90, 0, 255) parrot_6 = (175, 0, 255) parrot_7 = (255, 0, 200) parrot_8 = (255, 0, 125) parrot_9 = (255, 0, 0) colors = (parrot_0, parrot_1, parrot_2, parrot_3, parrot_4, parrot_5, parrot_6, parrot_7, parrot_8, parrot_9) # setup using crickit neopixel library crickit.init_neopixel(1) crickit.neopixel.fill((parrot_0)) # counter for party parrot colors z = 0 # speed for the dc motor speed = 0.3 while True: # begin the dc motor # will run throughout the loop motor.throttle = speed # read the input from the photo interrupter data = ss.digital_read(photo) # if the photo interrupter detects a break:
crickit.servo_1.actuation_range = 135 crickit.servo_1.set_pulse_width_range(min_pulse=850, max_pulse=2100) # You can assign a device to a variable to get a shorter name. servo_2 = crickit.servo_2 servo_2.throttle = 0 # Run a continous servo on Servo 2 backwards at half speed. crickit.continuous_servo_2.throttle = -0.5 # Run the motor on Motor 1 terminals at half speed. crickit.dc_motor_1.throttle = 0.5 # Set Drive 1 terminal to 3/4 strength. crickit.drive_1.fraction = 0.75 if crickit.touch_1.value: print("Touched terminal Touch 1") # A single stepper motor uses up all the motor terminals. crickit.stepper_motor.onestep(direction=stepper.FORWARD) # You can also use the Drive terminals for a stepper motor crickit.drive_stepper_motor.onestep(direction=stepper.BACKWARD) # Note: On CPX Crickit, NeoPixel pin is normally connected to A1, not to seesaw, # so this part of the demo cannot control the NeoPixel terminal. # Strip or ring of 8 NeoPixels crickit.init_neopixel(8) crickit.neopixel.fill((100, 100, 100))
# Crickit library demo - NeoPixel terminal # Note: On CPX Crickit, NeoPixel pin is normally connected to A1, not to seesaw, # so this demo would not control the NeoPixel terminal. # On the Crickit FeatherWing, the NeoPixel terminal is controlled by seesaw. # pylint can't figure out "np" can be indexed. # pylint: disable=unsupported-assignment-operation import time from adafruit_crickit import crickit # Strip or ring of 8 NeoPixels crickit.init_neopixel(8) crickit.neopixel.fill(0) # Assign to a variable to get a short name and to save time. np = crickit.neopixel while True: np.fill(0) time.sleep(1) np[0] = (100, 0, 0) np[1] = (0, 100, 0) np[2] = (0, 0, 100) time.sleep(1) np.fill((100, 100, 100)) time.sleep(1)
9: 18, 10: 0 } # Previous version: # SERVO_ANGLES = {0:0, 1:18, 2:36, 3:54, 4:72, 5:90, 6:108, 7:126, 8:144, 9:162, 10:180} # Folder names for music groups: START_GROUP_PATH = "/home/pi/love-meter/startup/" GROUP1_PATH = "/home/pi/love-meter/group1/" GROUP2_PATH = "/home/pi/love-meter/group2/" GROUP3_PATH = "/home/pi/love-meter/group3/" GROUP4_PATH = "/home/pi/love-meter/group4/" # Assuming servo is connected to servo1 connector. Change this if using a different port. METER_SERVO = crickit.servo_1 # Initialize LED connected to neopixel port and turn them off to begin with. NUMBER_OF_LEDS = 2 crickit.init_neopixel(NUMBER_OF_LEDS) LED = crickit.neopixel LED.fill(0) # Color definitions # Note that Connor's hardware uses green-red-blue instead of red-green-blue. YELLOW = (255, 255, 0) GREEN = (255, 0, 0) BLUE = (0, 0, 255) RANDOM_COLOR = (randint(80, 255), randint(80, 255), randint(80, 255)) OFF = 0 # Time interval that touchpads need to be touched in order to be triggered, in seconds (decimals allowed): # TOUCHPAD_SENSITIVITY = 1.0 # This next one isn't currently used. # HANDLE_SENSITIVITY = TOUCHPAD_SENSITIVITY # Input devices HANDLE = crickit.touch_1
# For use with the Adafruit BlueFruit LE Connect app. # Works with CircuitPython 4.0.0-beta.1 and later running on an nRF52840 board. import random import time from adafruit_crickit import crickit from adafruit_ble.uart import UARTServer from adafruit_bluefruit_connect.packet import Packet # Only the packet classes that are imported will be known to Packet. from adafruit_bluefruit_connect.color_packet import ColorPacket from adafruit_bluefruit_connect.button_packet import ButtonPacket # Initialize the NeoPixel ring to a fire color, not too bright. crickit.init_neopixel(24, brightness=0.1) color = (25, 12, 0) # Creates a sparkly "fire"-like effect. def sparkle(): crickit.neopixel[random.randrange(24)] = (0, 0, 0) crickit.neopixel[random.randrange(24)] = color crickit.neopixel[random.randrange(24)] = color crickit.neopixel[random.randrange(24)] = color uart_server = UARTServer() # Increase this to slow down movement of the servo arm. DELAY = 0.0 # Angle for Blinka before jumping through the ring.
clock_sound, brightness=0.5, debug=False) pybadge_disp.battery = (batt.value / 65520) * 6.6 # REPL display repl_disp = ReplDisplay(clock_zone, clock_24_hour, clock_auto_dst, clock_sound, debug=False) ### Instatiate Crickit from adafruit_crickit import crickit crickit.init_neopixel(1, brightness=0.01) # must call this first crickit.onboard_pixel.brightness = 0.01 crickit.onboard_pixel[0] = (0, 255, 0) # green for startup # Energize the power indicator crickit.feather_drive_2.fraction = 0.5 # power indicator ### Instatiate whistle servos # reset servo to start position and disable crickit.servo_1.angle = servo_1_start crickit.servo_2.angle = servo_2_start time.sleep(0.25) crickit.servo_1.angle = None # disable servo crickit.servo_2.angle = None time.sleep(0.5) """# calibrate servos at end position and disable
# Adapted from # https://github.com/adafruit/Adafruit_CircuitPython_Crickit/blob/master/examples/crickit_neopixel_simpletest.py # Crickit library demo - NeoPixel terminal # Note: On CPX Crickit, NeoPixel pin is normally connected to A1, not to seesaw, # so this demo would not control the NeoPixel terminal. # On the Crickit FeatherWing, the NeoPixel terminal is controlled by seesaw. # pylint can't figure out "np" can be indexed. # pylint: disable=unsupported-assignment-operation import time from adafruit_crickit import crickit # Strip or ring of 2 NeoPixels crickit.init_neopixel(2) crickit.neopixel.fill(0) # Assign to a variable to get a short name and to save time. np = crickit.neopixel RED = (255,0,0) GREEN = (0,255,0) BLUE = (0,0,255) # Show a sequence of red, green, blue. np.fill(0) time.sleep(1) np.fill(RED) time.sleep(1) np.fill(0)
red_led = digitalio.DigitalInOut(board.RED_LED) blue_led.direction = digitalio.Direction.OUTPUT red_led.direction = digitalio.Direction.OUTPUT ble = BLERadio() uart_service = UARTService() advertisement = ProvideServicesAdvertisement(uart_service) # motor setup motor_1 = crickit.dc_motor_1 motor_2 = crickit.dc_motor_2 FWD = -1.0 REV = 0.7 crickit.init_neopixel(24, brightness=0.2) # create Crickit neopixel object RED = (200, 0, 0) GREEN = (0, 200, 0) BLUE = (0, 0, 200) PURPLE = (120, 0, 160) YELLOW = (100, 100, 0) AQUA = (0, 100, 100) color = PURPLE # current NeoPixel color prior_color = PURPLE # to store state of previous color when changing them crickit.neopixel.fill(color) print("BLE Rover") print("Use Adafruit Bluefruit app to connect") while True: blue_led.value = False ble.start_advertising(advertisement)