I am trying to make a GPIO trigger by time.
The first part is just a test, the second part is a WHILE is to trigger the time, I used a IF statement to match the time I wanted. That worked very fine. But inside the While python gives me an error stating
AttributeError: 'str' object has no attribute 'sleep'
I try to evoke:
from time import sleep
But still gives me error.
Here is the code:
import RPi.GPIO as GPIO
import datetime
import time
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(26, GPIO.OUT)
GPIO.output(26, GPIO.LOW) #Turns On
time.sleep(3)
GPIO.output(26, GPIO.HIGH) #Turns off
print(datetime.datetime.now().strftime("%H:%M"))
while True :
time = datetime.datetime.now().strftime("%H:%M")
print(time)
if time == "06:16":
GPIO.output(26, GPIO.LOW)
time.sleep(2) # <===== This gives me error
GPIO.output(26, GPIO.HIGH)
time.sleep(1)
print("YEah baby")
break
GPIO.cleanup()