Joy-it RB-P-XPLR-SET handleiding

37 pagina's
PDF beschikbaar

Handleiding

Je bekijkt pagina 23 van 37
23
from machine import Pin, PWM
from utime import sleep
# Servo pin numbers
servoOnePin = 7
# Key pin numbers
buttonLeftPin = 15
buttonRightPin = 11
# Initialization of the servo
servoOne = PWM(Pin(servoOnePin))
# Initialize the buttons with PULL_UP to use the default HIGH state
buttonLeft = Pin(buttonLeftPin, Pin.IN, Pin.PULL_UP)
buttonRight = Pin(buttonRightPin, Pin.IN, Pin.PULL_UP)
# Servo speeds in nanoseconds
leftSpeed = 1300000 # Moves the servo to the left
rightSpeed = 1700000 # Moves the servo to the right
# Servo frequency
servoOne.freq(50) # Typical servo frequency of 50Hz
# Status of the servo
servoState = 'left' # Starts with counterclockwise rotation
# Last state of the buttons to recognize edges
lastButtonLeft = buttonLeft.value()
lastButtonRight = buttonRight.value()
while True:
# Read out the current status of the buttons
currentButtonLeft = buttonLeft.value()
currentButtonRight = buttonRight.value()
# Check whether an edge from HIGH to LOW was detected (button was pressed)
if lastButtonLeft == 1 and currentButtonLeft == 0:
servoState = 'right' # Changes the direction to the right when the left
button is pressed
elif lastButtonRight == 1 and currentButtonRight == 0:
servoState = 'left' # Changes the direction to the left when the right
button is pressed
SUMMARY: We control our servomotor and let it switch between le and right rotation, controlled by our buttons.
Checking the buttons
Initialization of the servomotor and
buttons

Bekijk gratis de handleiding van Joy-it RB-P-XPLR-SET, stel vragen en lees de antwoorden op veelvoorkomende problemen, of gebruik onze assistent om sneller informatie in de handleiding te vinden of uitleg te krijgen over specifieke functies.

Productinformatie

MerkJoy-it
ModelRB-P-XPLR-SET
CategorieNiet gecategoriseerd
TaalNederlands
Grootte21690 MB