def senLevel(self,senPin,senLevel=None): ## currentTime=time.time()%60 ## while not time.time()%60 == currentTime: for x in range(10): value=ultrasonic(senPin,senLevel) if value==True: print("{} level is good".format("oil" if senPin==5 else "water")) return True else: print("{} is not enough ".format("oil" if senPin==5 else "water")) return False break senDict.append(value) ## print(senDict) try: if mean(senDict) > 1: print("{} sensor is Working".format("oilSensor" if senPin==5 else "waterSensor")) del senDict[:] return True else: print("{} sensor is not working".format(senPin)) del senDict[:] return True except RuntimeWarning: return True
def cleanCycle(clean_mode, delay): popup.destroy() if GPIO.input(wasteWaterPin) != True: print("cleaning") if ultrasonic(water_pin) > minCleanWater: print("cleaning is running") GPIO.output(clean_pin, True) stepper_motion(clean_mode, delay, clean_speed) GPIO.output(clean_pin, False) GPIO.output(clean_out, True) else: print("water is not enough") print("water level", ultrasonic(water_pin)) else: popupmsg("waste water is full", cleanCycle( "backward", 15, ))
def diagnosticCycle(dictionary): for u in dictionary: for x in range(10): reading = ultrasonic(u) readingDict.append(u) avg = sum(readingDict) / float(len(readingDict)) if all(x == readingDict[0] for x in items) == True: print("sensor failed") else: print("sensor is working")
def ultrasonicDetection(ultrasonicDictionary): print("sensing") for u in ultrasonicDictionary: # including ultrasonic dictionary reading = ultrasonic(u) if reading > maxOilLevel and reading < minOilLevel: print("sensor failed or fill the oil container") print(reading) else: print("sensor working", reading) return True
def levelSensing(ultrasonicDictionary): print("sensing") for u in ultrasonicDictionary: reading = ultrasonic(u) if reading < requiredWaterLevel: print("Drink is not enough, checkreading: " + str(reading)) pour_thread.acquire() else: print(reading) pour_thread.release()
def ultrasonic(ultrasonicDictionary): print("sensing") for u in ultrasonicDictionary: reading=ultrasonic(u) if reading < minOilLevel: print("oil is not enough, checkreading: " + str(reading)) start_process.acquire() elif reading < minwaterLevel: print("water is not enough, check reading: "+str(reading)) lock.acquire() else: print(str(reading)) lock.release()
def getUltrasonicReading(pinNo): return ultrasonic(pinNo)
import RPi.GPIO as GPIO import pins from ultra import ultrasonic ultrasonicDictionary = [14, 15, 16, 17, 18, 27] # contains ultrasonic sensor echo pin numbers readingDict = [] requiredWaterLevel = 10 for u in ultrasonicDictionary: reading = ultrasonic(u) readingDict.append(reading) if reading < requiredWaterLevel: print("water is not enough, reading: " + str(reading)) else: print(reading) def diagnosticCycle(dictionary): for u in dictionary: for x in range(10): reading = ultrasonic(u) readingDict.append(u) avg = sum(readingDict) / float(len(readingDict)) if all(x == readingDict[0] for x in items) == True: print("sensor failed") else: print("sensor is working") print(avg) print(readingDict)