We met with Garth earlier today and were able to transfer data back and forth to eachother through MQTT! We updated the code, to take account of the data being processed into the command, as well as adjusting the collaboration of the sensor pad. Our next goal is to incorporate another sensor pad so we can control speed along with the direction of the puppets. We have also made plans to come together and assemble the environment that the puppets will be in. We would like to invite other students visit our puppet show this weekend if they would like to participate!

import time
import supervisor
import sys

# Import the low-level hardware libraries.
import board
import digitalio
import analogio
import pwmio

from adafruit_circuitplayground import cp
from adafruit_motor import servo


# ----------------------------------------------------------------
# Initialize hardware.

# Create a PWMOut object on pad SDA A5 to generate control signals.
pwm = pwmio.PWMOut(board.A5, duty_cycle=0, frequency=50)

# Create a Servo object which controls a hobby servo using the PWMOut.
actuator = servo.Servo(pwm, min_pulse=1000, max_pulse=2000)


# Create a PWMOut object on pad SCL A4 to generate control signals.
pwm2 = pwmio.PWMOut(board.A4, duty_cycle=0, frequency=50)

# Create a Servo object which controls a hobby servo using the PWMOut.
actuator2 = servo.Servo(pwm2, min_pulse=1000, max_pulse=2000)

# Configure the digital input pin used for its pullup resistor bias voltage.
bias = digitalio.DigitalInOut(board.D10)
bias.switch_to_input(pull=digitalio.Pull.UP)

# Configure the analog input pin used to measure the sensor voltage.
sensor = analogio.AnalogIn(board.A2)
scaling = sensor.reference_voltage / (2**16)


last_touch = 0
touched_arm_one = 0
touched_arm_two = 0
touched_leg_one = 0
touched_leg_two = 0

def flush_check():
    if supervisor.runtime.serial_bytes_available:
        line = sys.stdin.readline()


# ----------------------------------------------------------------
# Begin the main processing loop.
while True:
    # Read the integer sensor value and scale it to a value in Volts.
    volts = sensor.value * scaling
    touched_arm_one = 0
    pressure_one = (3.2 - volts) / (3.2 - 0.4)
    print(pressure_one) #function to send data 
    pressure_two = (1.4 - volts) / (1.4 - 0.1)

    if supervisor.runtime.serial_bytes_available:
            line = sys.stdin.readline()
            tokens = line.split()
            if len(tokens) == 1 and float(tokens[0]) > .90:
                touched_arm_one = 1

    if touched_arm_one:
        for angle in range(0, 180, 5):
            actuator.angle = angle
            time.sleep(0.02)
            flush_check()
        for angle in range(180, 0, -5):
            actuator.angle = angle
            time.sleep(0.02)
            flush_check()
    time.sleep(.5)