-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode2.py
More file actions
43 lines (36 loc) · 1.02 KB
/
code2.py
File metadata and controls
43 lines (36 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
## ---- Imports ---- ##
from piper_blockly import *
import board
import time
from digitalio import Pull
## ---- Definitions ---- ##
GP0 = piperServoPin(board.GP0, "GP0")
try:
set_digital_view(True)
except:
pass
GP2 = piperPin(board.GP2, "GP2")
GP1 = piperServoPin(board.GP1, "GP1")
# Define a variable to track the number of feedings
num_feedings = 0
max_feedings = 10 # Define the maximum number of feedings before considering the robot full
# Function to perform feeding action
def feed_robot():
global num_feedings
if num_feedings < max_feedings:
playSound("drumkit-Clap1")
print('High')
GP1.setServoAngle(0)
time.sleep(1)
GP1.setServoAngle(180)
time.sleep(0.6)
num_feedings += 1
else:
print("Robot is full, cannot eat anymore.")
# Main loop
playSound("electro-NightRoll-A")
GP0.setServoFraction(min(max(50 * 0.0018 + 0.5, 0), 1))
while True:
if GP2.checkPin(None):
feed_robot()
time.sleep(0.5)