diff --git a/kamera_server.py b/kamera_server.py index 735bcfa..cecbfc7 100644 --- a/kamera_server.py +++ b/kamera_server.py @@ -14,18 +14,23 @@ pins = { } # Set each pin as an output and make it low: -for pin in pins: - GPIO.setup(pin, GPIO.OUT) - GPIO.output(pin, GPIO.HIGH) +for pin in pins_out: + GPIO.setup(pins_out[pin]['nr'], GPIO.OUT) + GPIO.output(pins_out[pin]['nr'], GPIO.HIGH) for pin in pins_in: GPIO.setup(pins_in[pin]['nr'], GPIO.IN) +for key, value in pins_pwm.items(): + value['pwm'].start(0) + value['pwm'].ChangeFrequency(freq) + value['pwm'].ChangeDutyCycle(0) + @kamera_server.route("/") def main(): # For each pin, read the pin state and store it in the pins dictionary: - for pin in pins: - pins[pin]['state'] = GPIO.input(pin) + for pin in pins_out: + pins[pin]['state'] = GPIO.input(pins_out[pin]['nr']) for pin in pins_in: pins_in[pin]['state'] = GPIO.input(pins_in[pin]['nr']) @@ -55,8 +60,8 @@ def action(changePin, action): message = "Turned " + deviceName + " off." # For each pin, read the pin state and store it in the pins dictionary: - for pin in pins: - pins[pin]['state'] = GPIO.input(pin) + for pin in pins_out: + pins_out[pin]['state'] = GPIO.input(pins_out[pin]['nr']) for pin in pins_in: pins_in[pin]['state'] = GPIO.input(pins_in[pin]['nr']) diff --git a/src/pins.py b/src/pins.py index 088dcc9..6ab6fff 100644 --- a/src/pins.py +++ b/src/pins.py @@ -1,27 +1,29 @@ import RPi.GPIO as GPIO +freq = 800 + pins_out = { - 'kamera' : 2, - 'encoder' : 3 + 'kamera' : {'nr' : 2, 'name' : 'Relais, Kamera', 'state' : GPIO.HIGH}, + 'encoder' : {'nr' : 3, 'name' : 'Relais, Encoder', 'state' : GPIO.HIGH} } pins_in = { 'endschalter1' : {'nr' : 23, 'name' : 'Endschalter, Motor 1', 'state' : GPIO.HIGH}, 'endschalter2' : {'nr' : 26, 'name' : 'Endschalter, Motor 2', 'state' : GPIO.HIGH}, - 'endschalter3' : {'nr' : 25, 'name' : 'Endschalter, Motor 2', 'state' : GPIO.HIGH} + 'endschalter3' : {'nr' : 25, 'name' : 'Endschalter, Motor 3', 'state' : GPIO.HIGH} } pins_pwm = { - 'm1_a1' : 17, - 'm1_b1' : 18, - 'm1_a2' : 27, - 'm1_b2' : 22, - 'm2_a1' : 19, - 'm2_b1' : 13, - 'm2_a2' : 6, - 'm2_b2' : 5, - 'm3_a1' : 16, - 'm3_b1' : 12, - 'm3_a2' : 21, - 'm3_b2' : 20, + 'm1_a1' : {'nr' : 17, 'typ' : GPIO.setup(17, GPIO.OUT), 'pwm' : GPIO.PWM(17, freq)}, + 'm1_b1' : {'nr' : 18, 'typ' : GPIO.setup(18, GPIO.OUT), 'pwm' : GPIO.PWM(18, freq)}, + 'm1_a2' : {'nr' : 27, 'typ' : GPIO.setup(27, GPIO.OUT), 'pwm' : GPIO.PWM(27, freq)}, + 'm1_b2' : {'nr' : 22, 'typ' : GPIO.setup(22, GPIO.OUT), 'pwm' : GPIO.PWM(22, freq)}, + 'm2_a1' : {'nr' : 19, 'typ' : GPIO.setup(19, GPIO.OUT), 'pwm' : GPIO.PWM(19, freq)}, + 'm2_b1' : {'nr' : 13, 'typ' : GPIO.setup(13, GPIO.OUT), 'pwm' : GPIO.PWM(13, freq)}, + 'm2_a2' : {'nr' : 6, 'typ' : GPIO.setup(6, GPIO.OUT), 'pwm' : GPIO.PWM(6, freq)}, + 'm2_b2' : {'nr' : 5, 'typ' : GPIO.setup(5, GPIO.OUT), 'pwm' : GPIO.PWM(5, freq)}, + 'm3_a1' : {'nr' : 16, 'typ' : GPIO.setup(16, GPIO.OUT), 'pwm' : GPIO.PWM(16, freq)}, + 'm3_b1' : {'nr' : 12, 'typ' : GPIO.setup(12, GPIO.OUT), 'pwm' : GPIO.PWM(12, freq)}, + 'm3_a2' : {'nr' : 21, 'typ' : GPIO.setup(21, GPIO.OUT), 'pwm' : GPIO.PWM(21, freq)}, + 'm3_b2' : {'nr' : 20, 'typ' : GPIO.setup(20, GPIO.OUT), 'pwm' : GPIO.PWM(20, freq)} } \ No newline at end of file