I’m doing a home project with a raspi and a rain sensor.
Basically, with cronjobs, i run isitraining.py every 30 min.
If it is raining, i want it to increment a specific variable from another module (rains.water)
If it stops raining, i want it to decrease the same variable.
here are my codes:
import RPi.GPIO as GPIO import rains GPIO.setmode(GPIO.BCM) GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP) def raincounter(): if (GPIO.input(4) and (0<rains.water<13)): rains.water-=1 #No Rain elif (GPIO.input(4)==0 and (0<rains.water<13)): rains.water+=1 #Rain
import rains import isitraining isitraining.raincounter() print (rains.water)
everytime i run the “testscript.py” for the first time, it does modify the “rains.water” variable but only one time, if i run the script any other time after that, it does not increment or decrease in value.
gpio.input(4) is a rain sensor with digital input. When it’s high, it means there’s no rain and when it’s low it means it is raining.