Last active
June 11, 2025 11:39
-
-
Save DrTom/14c6b76c693f842a15f639aa066dadeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from neopixel import NeoPixel | |
from pupremote import PUPRemoteSensor | |
from machine import Pin, PWM | |
### Neopixel setup ############################################################# | |
np = NeoPixel(Pin(25), 1) # onboard neopixel | |
np[0] = (100, 100, 100) | |
np.write() | |
def led(r, g, b): | |
print(r, g, b) # prove that communication is working | |
np[0] = (r, g, b) | |
np.write() # write the color buffer to the led | |
return r, g, b # return the values to the caller | |
#### Servos ###################################################### | |
MIN_DC_NS = 500_000 | |
MAX_DC_NS = 2500_000 | |
MIN_ANGLE = +180 | |
MAX_ANGLE = -180 | |
# Sevro 1 bis 4 entsprehend den Pins 19 bis 22 | |
servo_p19 = PWM(Pin(19), freq=50) | |
servo_p20 = PWM(Pin(20), freq=50) | |
servo_p21 = PWM(Pin(21), freq=50) | |
servo_p22 = PWM(Pin(22), freq=50) | |
def servo_set_angle(servo, angle): | |
norm_angle = (angle + 180) / 360 | |
print("norm_angle:", norm_angle) | |
duty_ns = int(MIN_DC_NS + (MAX_DC_NS - MIN_DC_NS) * norm_angle) | |
print("duty_ns:", duty_ns) | |
servo.duty_ns(duty_ns) | |
def s19(angle): | |
servo_set_angle(servo_p19, angle) # move the servo to the specified angle | |
return angle # return the angle to the caller | |
def s20(angle): | |
servo_set_angle(servo_p21, angle) # move the servo to the specified angle | |
return angle # return the angle to the caller | |
def s21(angle): | |
servo_set_angle(servo_p21, angle) # move the servo to the specified angle | |
return angle # return the angle to the caller | |
def s22(angle): | |
servo_set_angle(servo_p21, angle) # move the servo to the specified angle | |
return angle # return the angle to the caller | |
rs = PUPRemoteSensor(power=True) | |
rs.add_command('led', 'BBB', 'BBB') | |
rs.add_command('s19', 'h', 'h') | |
rs.add_command('s20', 'h', 'h') | |
rs.add_command('s21', 'h', 'h') | |
rs.add_command('s22', 'h', 'h') | |
rs.process() | |
while True: | |
rs.process() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment