def main(): # Attach gas sensor to AIO0 myMQ2 = upmGas.MQ2(0); ## Exit handlers ## # This function stops python from printing a stacktrace when you hit control-C def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit, including functions from myMQ2 def exitHandler(): print("Exiting") sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) threshContext = upmGas.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 # Infinite loop, ends when script is cancelled # Repeatedly, take a sample every 2 microseconds; # find the average of 128 samples; and # print a running graph of dots as averages mybuffer = upmGas.uint16Array(128) while(1): samplelen = myMQ2.getSampledWindow(2, 128, mybuffer) if samplelen: thresh = myMQ2.findThreshold(threshContext, 30, mybuffer, samplelen) myMQ2.printGraph(threshContext, 5) if(thresh): print("Threshold is ", thresh)
def main(): # Attach gas sensor to Analog A0 sensor = upmGAS.MQ6(0) ## Exit handlers ## # This function stops python from printing a stacktrace when you hit control-C def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit, including functions from sensor def exitHandler(): print("Exiting") sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) threshContext = upmGAS.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 # Infinite loop, ends when script is cancelled # Repeatedly, take a sample every 2 microseconds; # find the average of 128 samples; and # print a running graph of asteriskss as averages mybuffer = upmGAS.uint16Array(128) while (1): samplelen = sensor.getSampledWindow(2, 128, mybuffer) if samplelen: thresh = sensor.findThreshold(threshContext, 30, mybuffer, samplelen) sensor.printGraph(threshContext, 5)
def main(): front = upmGas.MQ5(1) right = upmGas.MQ3(2) left = upmGas.MQ3(0) threshContext = upmGas.thresholdContext() global current_level ## Exit handlers ## # This function stops python from printing a stacktrace when you hit control-C def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit, including functions from myMQ5 def exitHandler(): print("Exiting") sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) while(1): left_reading = left.getSample() front_reading = front.getSample() right_reading = right.get_Sample() # add conditional for if 2 of 3 senors are equal if left_reading <= current_level and right_reading <= current_level and front_reading <= current_level: if current_level is None: else: return else if left_reading > right_reading and left_reading > front_reading: current_level = left_reading # move left else if right_reading > left_reading and right_reading > front_reading: current_level = right_reading # move right else if front_reading >= left_reading and front_reading >= right_reading: current_level = front_reading