2 scripts toegevoegd die worden niet gebruikt
This commit is contained in:
parent
4415a10acd
commit
c02bb60c97
42
not_used/afstandsensor.py
Normal file
42
not_used/afstandsensor.py
Normal file
@ -0,0 +1,42 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
GPIO.setmode( GPIO.BCM )
|
||||
GPIO.setwarnings( 0 )
|
||||
|
||||
print( "sr04 print" )
|
||||
|
||||
sr04_trig = 10
|
||||
sr04_echo = 11
|
||||
|
||||
GPIO.setup( sr04_trig, GPIO.OUT )
|
||||
GPIO.setup( sr04_echo, GPIO.IN, pull_up_down=GPIO.PUD_DOWN )
|
||||
|
||||
def sr04( trig_pin, echo_pin ):
|
||||
"""
|
||||
Return the distance in cm as measured by an SR04
|
||||
that is connected to the trig_pin and the echo_pin.
|
||||
These pins must have been configured as output and input.s
|
||||
"""
|
||||
|
||||
GPIO.output(trig_pin, False) # altijd met false starten
|
||||
time.sleep(0.5)
|
||||
GPIO.output(trig_pin, True)
|
||||
time.sleep(0.00001) # pulse trigger
|
||||
GPIO.output(trig_pin, False)
|
||||
|
||||
while GPIO.input(echo_pin) == False:
|
||||
start_time = time.time() # tijd opslaan wanneer de echo false is
|
||||
|
||||
while GPIO.input(echo_pin) == True:
|
||||
end_time = time.time() # tijd opslaan wanneer de echo true is
|
||||
|
||||
total_time = end_time - start_time # totaal aantal afstand in seconden
|
||||
return (round(total_time*34300/2, 2), total_time) #tuple terug geven met afstand in cm en totaal aantal seconden
|
||||
# sensor is niet helemaal naukeurig(~1-2cm variatie), kan ook aan de rpi timing liggen
|
||||
|
||||
try:
|
||||
while True:
|
||||
print( sr04( sr04_trig, sr04_echo ))
|
||||
time.sleep( 0.5 )
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
49
not_used/schuifregister.py
Normal file
49
not_used/schuifregister.py
Normal file
@ -0,0 +1,49 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings( 0 )
|
||||
|
||||
print( "hc595 walk" )
|
||||
|
||||
shift_clock_pin = 17 # let op de pinnen zijn aangepast!
|
||||
latch_clock_pin = 27
|
||||
data_pin = 22
|
||||
|
||||
GPIO.setup( shift_clock_pin, GPIO.OUT )
|
||||
GPIO.setup( latch_clock_pin, GPIO.OUT )
|
||||
GPIO.setup( data_pin, GPIO.OUT )
|
||||
|
||||
def hc595( shift_clock_pin, latch_clock_pin, data_pin, value, delay ):
|
||||
|
||||
for k in range(0, 8): # 8 keer loopen
|
||||
if value % 2 == 1: # als waarde oneven is
|
||||
GPIO.output(data_pin, GPIO.HIGH) # data pin hoog zetten
|
||||
else: # waarde is even
|
||||
GPIO.output(data_pin, GPIO.LOW) # data pin laag houden
|
||||
value = value // 2 # waarde halveren
|
||||
|
||||
GPIO.output(shift_clock_pin, GPIO.HIGH) # klok hoog, om de waarde pin te laten aflezen
|
||||
GPIO.output(shift_clock_pin, GPIO.LOW) # klok laag, default positie
|
||||
|
||||
|
||||
GPIO.output(latch_clock_pin, GPIO.HIGH) # geen idee, waarschijnlijk om de waardes op te laten slaan in de chip
|
||||
GPIO.output(latch_clock_pin, GPIO.LOW) # default positie
|
||||
time.sleep(delay)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
delay = 0.1
|
||||
try:
|
||||
while True:
|
||||
hc595( shift_clock_pin, latch_clock_pin, data_pin, 1, delay ) # waarde is 1 dus de eerste led hoort te branden de rest niet
|
||||
hc595( shift_clock_pin, latch_clock_pin, data_pin, 2, delay ) # waarde is 2 dus de tweede led en niet de 1e hoort te branden
|
||||
hc595( shift_clock_pin, latch_clock_pin, data_pin, 4, delay ) # waarde is 4 dus de 3e led hoort te branden de rest niet
|
||||
hc595( shift_clock_pin, latch_clock_pin, data_pin, 8, delay ) # enzovoort
|
||||
hc595( shift_clock_pin, latch_clock_pin, data_pin, 16, delay )
|
||||
hc595( shift_clock_pin, latch_clock_pin, data_pin, 32, delay )
|
||||
hc595( shift_clock_pin, latch_clock_pin, data_pin, 64, delay )
|
||||
hc595( shift_clock_pin, latch_clock_pin, data_pin, 128, delay ) # de 8e led en niet meer
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
Reference in New Issue
Block a user