import RPi.GPIO as GPIO import time import AirtablePancake at = AirtablePancake.at() p1 = 31 p2 = 29 GPIO.setmode(GPIO.BOARD) pin1 = GPIO.setup(p1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) pin2 = GPIO.setup(p2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # GRIDDLE MOTOR SETUP ---------------------------------------------------------- ena = 32 # Left motor enable (PWM) in1 = 18 # Left motor direction 1 in2 = 16 # Left motor direction 2 GPIO.setup(ena, GPIO.OUT) GPIO.setup(in1, GPIO.OUT) GPIO.setup(in2, GPIO.OUT) # Set all pins low to start (prevents movement at startup) GPIO.output(in1, GPIO.LOW) GPIO.output(in2, GPIO.LOW) # TABLE LIFT MOTOR SETUP ---------------------------------------------------------- ena2 = 33 # Left motor enable (PWM) in3 = 40 # Left motor direction 1 in4 = 38 # Left motor direction 2 GPIO.setup(ena2, GPIO.OUT) GPIO.setup(in3, GPIO.OUT) GPIO.setup(in4, GPIO.OUT) # Set all pins low to start (prevents movement at startup) GPIO.output(in3, GPIO.LOW) GPIO.output(in4, GPIO.LOW) # Create PWM instances (both motors at 50 Hz) motor1 = GPIO.PWM(ena, 50) # Left motor motor2 = GPIO.PWM(ena2, 50) # Left motor # Start PWM at 0% motor1.start(0) motor2.start(0) def forward(speed): GPIO.output(in1, GPIO.HIGH) GPIO.output(in2, GPIO.LOW) motor1.ChangeDutyCycle(speed) def back(speed): print("closing motor") GPIO.output(in1, GPIO.LOW) GPIO.output(in2, GPIO.HIGH) motor1.ChangeDutyCycle(speed) def stop(): GPIO.output(in1, GPIO.LOW) GPIO.output(in2, GPIO.LOW) motor1.ChangeDutyCycle(0) def table_forward(speed): GPIO.output(in3, GPIO.HIGH) GPIO.output(in4, GPIO.LOW) motor2.ChangeDutyCycle(speed) def table_back(speed): GPIO.output(in3, GPIO.LOW) GPIO.output(in4, GPIO.HIGH) motor2.ChangeDutyCycle(speed) def table_stop(): GPIO.output(in3, GPIO.LOW) GPIO.output(in4, GPIO.LOW) motor2.ChangeDutyCycle(0) def checkPosition(p1,p2,position): if GPIO.input(p1) == 0 and GPIO.input(p2) == 0: position = "moving" elif GPIO.input(p1) == 1: position = "top" elif GPIO.input(p2) == 1: position = "bottom" return position def cookPancake(): print("cooking pancake") cook_time = 1 for i in range(cook_time): print(i) time.sleep(1) print("done cooking pancake") def tableSequence(): while at.checkValue("Cooking 2 Status") != 1: time.sleep(0.3) print("Waiting for Cooking 2 Status of 1") #Raise table 1 table_back(100) time.sleep(0.3) table_stop() #Set Cooking 2 Status to 5 at.changeValue("Cooking 2 Status", 5) print("Table 2 Raised") #Read airtable until Cooking 2 Status is 7 while (at.checkValue("Cooking 2 Status") != 7): time.sleep(0.5) print("Waiting for Cooking 2 Status of 7") #Lower table 1 table_forward(20) time.sleep(0.3) table_stop() #Set Cooking 2 Status to 99 at.changeValue("Cooking 2 Status", 99) print("Table 2 Lowered") moving = 0 position = "bottom" try: while True: # determine current position and airtable value airtable = at.checkValue("Cooking 2 Status") print(airtable) position = checkPosition(p1,p2,position) print(position) # if the griddle is open and batter is done dispensing, close the griddle if (position != "bottom") and airtable == 2: position = "moving" back(20) moving = 1 while position == "moving" or position == "top": position = checkPosition(p1,p2,position) moving = 0 stop() print("griddle closed, motor off") # cook the pancake and update the airtable at.changeValue("Cooking 2 Status", 3) cookPancake() # open the griddle and update the airtable position = "moving" forward(30) moving = 1 while position == "moving" or position == "bottom": position = checkPosition(p1,p2,position) moving = 0 stop() print("griddle open, motor off") at.changeValue("Cooking 2 Status", 4) # START OF TABLE LIFT SEQUENCE tableSequence() time.sleep(0.5) except KeyboardInterrupt: GPIO.cleanup() print("done")