import RPi.GPIO as GPIO, time progName="Test_isTrueIfDark.py" print("always works with 2 diff. CD in series (covering both). ") print("works with 1 CD sometimes. ") print("from phys pin 38 (as input with PUD_DOWN)") print(" to phys pin 40 (as output High).") GPIO.setmode(GPIO.BCM) #BroadCoM numbering eg GPIO #s PIN=20 #phys pin 38 PINout=21 #phys pin 40 GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # on a Raspberry Pi, PullUpDown is a 10k resistor # a photoresist photocell (CD) when lit is 5k. GPIO.setup(PINout,GPIO.OUT) GPIO.output(PINout, True) print("turn phys pin 40 On") GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) def isTrueIfDark(PIN): #Purpose: to return True if both CDs are covered #By: D@CC on 2023JOct29 #Tested reading=GPIO.input(PIN) if reading: state=False else: state=True #if end #time.sleep(1) return state #def end while True: if isTrueIfDark(PIN): print("Dark") else: print("Light") #if end time.sleep(1) #while end