import RPi.GPIO as IO #calling for header file which helps in using GPIOs of PI import time IO.setwarnings(False) #do not show any warnings IO.setmode (IO.BCM) #programming the GPIO by BCM pin numbers IO.setup(19,IO.OUT) #initialize GPIO19 as an output IO.setup(21,IO.IN) #initialize GPIO21,20,16,12,23 as inputs IO.setup(20,IO.IN) IO.setup(16,IO.IN) IO.setup(12,IO.IN) IO.setup(23,IO.IN) p = IO.PWM(19,200) #GPIO19 is set as PWM output with frequency at 200Hz p.start(1) #start PWM output with 1% duty cycle while 1: if(IO.input(23) == False): #If AC power is OFF if(IO.input(16) == True): #If battery voltage >+12V if (IO.input(20) == True): #If its complete dark time.sleep(0.01) if (IO.input(20) == True): #If its complete dark p.ChangeDutyCycle(99) #change PWM duty cycle to 99% elif (IO.input(21) == True): #else If its semi dark time.sleep(0.01) if (IO.input(21) == True): #else If its semi dark p.ChangeDutyCycle(30) #change PWM duty cycle to 30% elif (IO.input(21) == False): #if its not even semi dark time.sleep(0.01) if (IO.input(21) == False): p.ChangeDutyCycle(0) #turn OFF the LAMP time.sleep(0.1) if(IO.input(23) == True): #If AC power is ON p.ChangeDutyCycle(0) #turn OFF the LAMP if(IO.input(16) == False): #If battery voltage <+12V p.ChangeDutyCycle(0) #turn OFF the LAMP