def main(): ldr_pin = int(os.environ.get('LDR_PIN', '17')) sensor = LightSensor(ldr_pin, charge_time_limit=0.005, threshold=0.1) time.sleep(3) # wait a bit for setup (initial capacitor charge) while True: sensor.wait_for_dark() alert() # Wait 5 seconds so as to not send a burst of alerts time.sleep(5)
def __iRDectector__(self): change_time = 0.0 read_value = False print("setting up pins") ir_light = LED(self.light) start_timer = time.perf_counter() ''' This that the time should be below 90.0 second or until the value does read as true it must be reaching the value ''' while (time.perf_counter() - start_timer) <= 90.0 or (read_value is True): finish_timer = time.perf_counter() print("Running with senors") #this is me setting up the ligth reflection with a certain threshold i_r_detection = LightSensor(self.reflection, threshold=.99) # this turn the light on for test reason ir_light.on() #this is a call to wait for light # this should allow for a better print out # it threshold is less then the intital call then it wouldn't detect if i_r_detection.wait_for_dark(): change_time = finish_timer - start_timer read_value = False #if the threshold is greater then the value it will return with a value of the changes elif i_r_dectection.wait_for_light(.001): change_time = finish_timer - start_timer read_value = True return abs(change_time)
#!/usr/bin/env python3 from gpiozero import LightSensor ldr = LightSensor(18) while True: ldr.wait_for_light() print(" light is on") ldr.wait_for_dark() print("light is off")
from gpiozero import LightSensor, LED from time import sleep light = LightSensor(4, charge_time_limit=0.001) buzzer = LED(26) buzzer.off() sleep(1) light.wait_for_dark() buzzer.on()
# Displays It's Light or Dark from gpiozero import LightSensor sensor = LightSensor(18) while True: sensor.wait_for_light() print("It's light...") sensor.wait_for_dark() print("It's dark...")
from gpiozero import LightSensor sensor = LightSensor(23) while True: sensor.wait_for_light() print("1") sensor.wait_for_dark() print("0")
from gpiozero import LightSensor # 100nF Capacitor and 1M Ohm CdS Cell ldr1 = LightSensor(11, queue_len=10, charge_time_limit=0.001, threshold=0.2) while True: ldr1.wait_for_light() print("It's light! :)") ldr1.wait_for_dark() print("It's dark... :(")
if currentForecast == 'Clear': print("The weather is clear!") #omxp = Popen(['omxplayer',movie4]) if currentForecast == 'Rain': print("The weather is rain!") #omxp = Popen(['omxplayer',movie3]) if currentForecast == 'Clouds': print("The weather is clouds!") #omxp = Popen(['omxplayer',movie2]) if currentForecast == 'Snow': print("The weather is snow!") #omxp = Popen(['omxplayer',movie1]) return while True: if lightSensor1.wait_for_dark(2): print("Sensor 1 is touched") currentForecast = weatherNow['weather'][0]['main'] playVideo(currentForecast) if lightSensor2.wait_for_dark(2): print("Sensor 2 is touched") currentForecast = weatherinNextThreeHours['weather'][0]['main'] playVideo(currentForecast) #Sensor 1 and 2 are dark (Use Case: Both are touched) if (lightSensor1.light_detected and lightSensor2.light_detected): print("Black screen to be displayed")
#!/usr/bin/python from gpiozero import LightSensor from time import sleep sensor = LightSensor(27,queue_len = 2) strikes = 0 balls = 0 print("New batter") try: while balls < 4 and strikes < 3: print("Pitch now. You have 5 seconds to pitch...") if sensor.wait_for_dark(5): strikes = strikes + 1 print("Strike!") else: balls = balls + 1 print("Ball :-(") print("Balls = %u; Strikes = %u" % (balls,strikes)) sensor.wait_for_light() sleep(5) if balls == 4: print("Walk to first") else: print("Your out!!!") except KeyboardInterrupt: print("Exiting early,,,")
playVideo ("Nothing") ##lightSensor1.when_dark=inputChng() ##lightSensor1.when_light=inputChng() ##lightSensor2.when_dark=inputChng() ##lightSensor2.when_light=inputChng() while True: print(lightSensor1.value) print(lightSensor2.value) print(lightSensor3.value) print(lightSensor4.value) print(lightSensor5.value) if lightSensor1.wait_for_dark(1) and sensortouched != 1: if (globalvar==1): print ('quiting when sensor1 touched, I am killing' , omxp.pid) #omxp.stdin.write(´q´) os.system('killall omxplayer.bin') globalvar =0 print ("Sensor 1 is touched") sensortouched = 1 CurrentresponseWeather = urllib.request.urlopen('http://api.openweathermap.org/data/2.5/weather?id=2673730&APPID=bfb8163bad72d71e9da0c72974a73828').read() print( CurrentresponseWeather) CurrentjsonResponse = json.loads(CurrentresponseWeather.decode('utf-8')) currentForecast = CurrentjsonResponse['weather'][0]['main'] print(currentForecast) playVideo (currentForecast)
from gpiozero import LightSensor ldr = LightSensor(23) i = 0 while True: #ldr.wait_for_light() #i+=1 #print("Light detected! ",i) if (ldr.wait_for_light()): i += 1 print("Light detected! ", i) if (ldr.wait_for_dark()): i += 1 print("No light detected", i)