Versuche jetzt nach Tagen sortiert.
This commit is contained in:
35
Versuchstag-1/aufgabe_a.py
Normal file
35
Versuchstag-1/aufgabe_a.py
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from time import sleep
|
||||
try:
|
||||
import RPi.GPIO as GPIO
|
||||
except RuntimeError:
|
||||
print("Error importing RPi.GPIO! Run this script as root.")
|
||||
exit(1)
|
||||
|
||||
LED_RED = 17
|
||||
LED_GREEN = 18
|
||||
|
||||
def setup():
|
||||
# Run GPIO with PI pin numbers.
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
# Set outputs fpr led pins
|
||||
GPIO.setup(LED_RED, GPIO.OUT)
|
||||
GPIO.setup(LED_GREEN, GPIO.OUT)
|
||||
|
||||
def main():
|
||||
setup()
|
||||
try:
|
||||
while True:
|
||||
GPIO.output(LED_RED, GPIO.HIGH)
|
||||
GPIO.output(LED_GREEn, GPIO.LOW)
|
||||
sleep(1)
|
||||
GPIO.output(LED_RED, GPIO.LOW)
|
||||
GPIO.output(LED_GREEn, GPIO.HIGH)
|
||||
sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
58
Versuchstag-1/aufgabe_b.py
Normal file
58
Versuchstag-1/aufgabe_b.py
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from time import sleep
|
||||
import threading
|
||||
try:
|
||||
import RPi.GPIO as GPIO
|
||||
except RuntimeError:
|
||||
print("Error importing RPi.GPIO! Run this script as root.")
|
||||
exit(1)
|
||||
|
||||
class LED(Thread):
|
||||
|
||||
def __init__(self, pin, frequency, use_pwm=False):
|
||||
Thread.__init__(self)
|
||||
self.__pin = pin
|
||||
self.__frequency
|
||||
self.__use_pwm = use_pwm
|
||||
self.__pwm = None
|
||||
|
||||
GPIO.setup(pin, GPIO.OUT)
|
||||
if use_pwm:
|
||||
self.__pwm = GPIO.PWM(pin, frequency)
|
||||
|
||||
def new_random_frequency(self):
|
||||
self.__frequency = random.randint(1, 100)
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
if self.__use_pwm:
|
||||
self.__pwm.start(0)
|
||||
while True:
|
||||
for s in range(0, 1, 0.1):
|
||||
self.__pwm.ChangeDutyCycle(math.sin(s * math.pi))
|
||||
#sleep(1 / self.__frequency)
|
||||
sleep(1)
|
||||
else:
|
||||
while True:
|
||||
GPIO.output(LED_GREEn, GPIO.LOW)
|
||||
sleep(1 / self.__frequency)
|
||||
GPIO.output(LED_GREEn, GPIO.HIGH)
|
||||
sleep(1 / self.__frequency)
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
||||
def setup():
|
||||
# Run GPIO with PI pin numbers.
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
|
||||
def main():
|
||||
setup()
|
||||
|
||||
# Pin, frequency in Hz
|
||||
led_thread = LED(17, 1000)
|
||||
led_thread.run()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
41
Versuchstag-1/aufgabe_c.py
Normal file
41
Versuchstag-1/aufgabe_c.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from time import sleep
|
||||
import threading
|
||||
|
||||
import aufgabe_b
|
||||
|
||||
try:
|
||||
import RPi.GPIO as GPIO
|
||||
except RuntimeError:
|
||||
print("Error importing RPi.GPIO! Run this script as root.")
|
||||
exit(1)
|
||||
|
||||
TASTER_PIN = 2
|
||||
|
||||
def setup():
|
||||
# Run GPIO with PI pin numbers.
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(TASTER_PIN, GPIO.IN)
|
||||
|
||||
def main():
|
||||
setup()
|
||||
|
||||
# Pin, frequency in Hz
|
||||
led_thread1 = LED(17, 1000)
|
||||
led_thread1.run()
|
||||
led_thread2 = LED(18, 1000)
|
||||
led_thread2.run()
|
||||
|
||||
# read taster
|
||||
try:
|
||||
while True:
|
||||
if GPIO.input(TASTER_PIN) == 1:
|
||||
print("Taster was pressed. Set new frequency.")
|
||||
led_thread1.new_random_frequency()
|
||||
led_thread2.new_random_frequency()
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
24
Versuchstag-1/aufgabe_e.sh
Normal file
24
Versuchstag-1/aufgabe_e.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
LED_RED="17"
|
||||
LED_GREEN="18"
|
||||
|
||||
# setup
|
||||
echo "Setup red led on pin $LED_RED"
|
||||
echo $LED_RED > /sys/class/gpio/export
|
||||
echo "out" > /sys/class/gpio/gpio$LED_RED/direction
|
||||
|
||||
echo "Setup red led on pin $LED_GREEN"
|
||||
echo $LED_GREEN > /sys/class/gpio/export
|
||||
echo "out" > /sys/class/gpio/gpio$LED_GREEN/direction
|
||||
|
||||
|
||||
while true; do
|
||||
echo "1" > /sys/class/gpio/gpio$LED_RED/value
|
||||
echo "0" > /sys/class/gpio/gpio$LED_GREEN/value
|
||||
sleep 1
|
||||
echo "0" > /sys/class/gpio/gpio$LED_RED/value
|
||||
echo "1" > /sys/class/gpio/gpio$LED_GREEN/value
|
||||
sleep 1
|
||||
done
|
||||
|
||||
12
Versuchstag-1/aufgabe_f.sh
Normal file
12
Versuchstag-1/aufgabe_f.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
TASTER_PIN="2"
|
||||
# setup
|
||||
echo "Setup taster on pin $TASTER_PIN"
|
||||
echo $TASTER_PIN > /sys/class/gpio/export
|
||||
echo "in" > /sys/class/gpio/gpio$TASTER_PIN/direction
|
||||
|
||||
while true; do
|
||||
echo -e "Taster sagt: "
|
||||
cat /sys/class/gpio/gpio$TASTER_PIN/value
|
||||
done
|
||||
26
Versuchstag-1/aufgabe_g.py
Normal file
26
Versuchstag-1/aufgabe_g.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from time import sleep
|
||||
import threading
|
||||
|
||||
import aufgabe_b
|
||||
|
||||
try:
|
||||
import RPi.GPIO as GPIO
|
||||
except RuntimeError:
|
||||
print("Error importing RPi.GPIO! Run this script as root.")
|
||||
exit(1)
|
||||
|
||||
def setup():
|
||||
# Run GPIO with PI pin numbers.
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
|
||||
def main():
|
||||
setup()
|
||||
|
||||
# Pin, frequency in Hz
|
||||
led_thread1 = LED(17, 1000, use_pwm=True)
|
||||
led_thread1.run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
19
Versuchstag-1/servoblaster_ctl.py
Normal file
19
Versuchstag-1/servoblaster_ctl.py
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
|
||||
def sb_write(fd, servo, pulse):
|
||||
try:
|
||||
os.write(fd, '%d=%d\n' % (servo,pulse))
|
||||
except IOError as e:
|
||||
print e
|
||||
|
||||
try:
|
||||
fd = os.open('/dev/servoblaster', os.O_WRONLY)
|
||||
except OSError as e:
|
||||
print 'could not open /dev/servoblaster'
|
||||
raise SystemExit(5)
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
os.close(fd)
|
||||
pass
|
||||
|
||||
|
||||
8
Versuchstag-1/setup.sh
Normal file
8
Versuchstag-1/setup.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
mkdir -p /home/pi/Group03/Versuch{1,2,3,4,5,6,7,8}
|
||||
cp -r /home/pi/src /home/pi/Group03/
|
||||
chown -R pi:pi /home/pi/Group03
|
||||
|
||||
echo "Aufgabe in:"
|
||||
grep -r --color AUFGABE /home/pi/Group03/src
|
||||
echo -e "\n\n"
|
||||
Reference in New Issue
Block a user