Пример #1
0
 def configure_digital(self, digital_in: [] = [], digital_out: [] = []):
     safe_print('Setting digital_in:', digital_in)
     safe_print('Setting digital_out:', digital_out)
     for pin in digital_out:
         GPIO.setup(pin, GPIO.OUT)
     for pin in digital_in:
         GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
     r = len(digital_in) + len(digital_out)
     return r
Пример #2
0
 def digital_out(self, pins=[], states=[]):
     safe_print('pins:', pins)
     safe_print('states:', states)
     for pin, state in zip(pins, states):
         GPIO.output(pin, state)
     return len(pins)
Пример #3
0
 def configure_pwm(self,
                   pins: [] = []):  # format [(pin, name, frequency), ...]
     for pin, name, freq in pins:
         safe_print('setting pwm:', pin, name, freq)
         self.pwm_objects[name] = GPIO.PWM(pin, freq)
Пример #4
0
 def test_host(self):
     safe_print('test success returning 1 as a response')
Пример #5
0
if __name__ == '__main__':

    pi_ip = '192.168.0.106'
    pi_port = 1857
    rc = RC_client(pi_ip, pi_port)
    rc.connect()
    # safe_print('testing digital')
    # rc.config_digital_output([18,])
    # flag = False
    # for i in range(5):
    #     flag = not flag
    #     rc.set_digital_pin(18, flag)
    #     time.sleep(1)

    safe_print('testing pwm')
    rc.config_pwm_pin(18, 'pwm0', 50)
    rc.start_pwm('pwm0', 0)

    # for i in range(5):
    #     for j in range(1,100,1):
    #         rc.change_pwm('pwm0', j)
    #         time.sleep(0.02)
    #     time.sleep(0.5)
    #     for j in range(100,0,-1):
    #         rc.change_pwm('pwm0', j)
    #         time.sleep(0.02)
    rc.change_pwm('pwm0', 30)
    time.sleep(2)

    rc.stop_pwm('pwm0')