Reputation: 11
I'm getting my code to work from my Wtime
function but after I set the waitTime
for my Wtime
, it doesn't translate over to my main
function. When I press my button for my LED to work I get:
time.sleep(waitTime)
TypeError: an integer is required (got type function)
This is my code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#leds
rled = 16
yled = 6
#btns
btnOnVal = 12
btnOffVal = 18
#ldr
ltSense = 21
GPIO.setup(rled, GPIO.OUT)
GPIO.setup(yled, GPIO.OUT)
GPIO.setup(btnOnVal, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(btnOffVal, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(ltSense, GPIO.IN, pull_up_down = GPIO.PUD_UP)
def Wtime():
try:
waitTime = float(input("Please enter a wait time for flashing lights(1 - 10 secs):"))
while (waitTime < 0 or waitTime > 10):
waitTime = float(input("Please enter a wait time for flashing lights(1 - 10 secs):"))
except:
print("Not Integer Value")
return waitTime
def rblink(waitTime):
GPIO.output(rled, GPIO.HIGH)
time.sleep(waitTime)
GPIO.output(rled, GPIO.LOW)
time.sleep(waitTime)
def yblink(waitTime):
GPIO.output(yled, GPIO.HIGH)
time.sleep(waitTime)
GPIO.output(yled, GPIO.LOW)
time.sleep(waitTime)
def main(waitTime):
while (GPIO.input(ltSense) == 1):
if (GPIO.input(btnOnVal) == False):
for i in range(0,10,1):
rblink(waitTime)
if (GPIO.input(btnOffVal) == False):
for i in range(0,10,1):
yblink(waitTime)
#function call
Wtime()
main(yblink)
How do I fix this error?
Upvotes: 0
Views: 562
Reputation: 20414
You need to pass the result of wTime()
into main()
:
main(Wtime())
Also, you should ideally start the names of functions with lowercase characters as the standard is uppercase characters for classes.
Upvotes: 3