def loop(): while True: readSensors() res = ADC0832.getResult() moisture = 255 - res # Msg2 = str('analog value: %03d moisture: %d' %(res, moisture)) Msg2 = str('moisture %d' % (moisture)) d = checkdist() df = "%0.2f" % d Msg3 = str('Distance %s' % df) res2 = ADC0832.getResult() - 80 if res2 < 0: res2 = 0 if res2 > 100: res2 = 100 # print ('res2 = %d' % res2) Msg4 = ('Light %d' % res2) res3 = ADC0832.getResult() Gas_concentration = res3 # print ('analog value: %03d Gas concentration: %d' %(res3, Gas_concentration)) Msg5 = str('Gas-concentration %d' % (Gas_concentration)) # d_time = datetime.datetime.now() d_date = datetime.datetime.now().date() d_time = datetime.datetime.now().time() d_time2 = d_time.strftime('%H:%M:%S') Msg6 = str(d_date) + ' ' + str( d_time2 ) + ' ' + Msg + ' ' + Msg2 + ' ' + Msg3 + ' ' + Msg4 + ' ' + Msg5 client.publish(Topic, Msg6) print(Msg6) time.sleep(360)
def sendResult(): coordinates = { "x": ADC0832.getResult(0), "y": ADC0832.getResult(1), "z": (GPIO.input(btn) == 0) } print(coordinates) sock.sendto(json.dumps(coordinates).encode(), (UDP_IP, UDP_PORT))
def joystickState(): if ADC0832.getResult1() == 0: return 1 #up if ADC0832.getResult1() == 255: return 2 #down if ADC0832.getResult() == 0: return 3 #left if ADC0832.getResult() == 255: return 4 #right
def joystickState(): if ADC0832.getResult1() == 0: return 1 #up if ADC0832.getResult1() == 255: return 2 #down if ADC0832.getResult() == 0: return 3 #left if ADC0832.getResult() == 255: return 4 #right
def getResult(): #get joystick result x_axis = 0 y_axis = 1 x = ADC0832.getResult(x_axis) if x == 0: return 4 elif x == 255: return 3 y = ADC0832.getResult(y_axis) if y == 0: return 1 elif y == 255: return 2
def getResult(): #get joystick result if ADC0832.getResult1() == 0: return 1 #up if ADC0832.getResult1() == 255: return 2 #down if ADC0832.getResult() == 0: return 3 #left if ADC0832.getResult() == 255: return 4 #right if GPIO.input(btn) == 1: print 'Button is pressed!' # Button pressed
def printResult(): #get joystick result if ADC0832.getResult(1) == 0: print('up') #up if ADC0832.getResult(1) == 255: print('down') #down if ADC0832.getResult(0) == 0: print('left') #left if ADC0832.getResult(0) == 255: print('right') #right if GPIO.input(btn) == 0: print('Button is pressed!') # Button pressed
def getResult(): #get joystick result x_axis = 0 y_axis = 1 x = ADC0832.getResult(x_axis) if x == 0: return 4 elif x == 255: return 3 y = ADC0832.getResult(y_axis) if y == 0: return 1 elif y == 255: return 2
def getResult(): #get joystick result if ADC0832.getResult1() == 0: return 1 #up if ADC0832.getResult1() == 255: return 2 #down if ADC0832.getResult() == 0: return 3 #left if ADC0832.getResult() == 255: return 4 #right if GPIO.input(btn) == 1: print 'Button is pressed!' # Button pressed
def getResult(): #get joystick result global xFlag, yFlag if ADC0832.getResult(1) == 0: xFlag = 1 #up if ADC0832.getResult(1) == 255: xFlag = 2 #down if ADC0832.getResult(0) == 0: yFlag = 1 #left if ADC0832.getResult(0) == 255: yFlag = 2 #right if GPIO.input(btn) == 0: print 'Button is pressed!' # Button pressed
def photo(): res = ADC0832.getResult() - 80 if res < 0: res = 0 if res > 100: res = 100 return res
def loop(): while True: readSensors() res = ADC0832.getResult() moisture = 255 - res Msg2 = str('moisture %d' %(moisture)) d = checkdist() df = "%0.2f" %d Msg3 = str('Distance %s' %df) d_date = datetime.datetime.now().date() d_time = datetime.datetime.now().time() d_time2 = d_time.strftime('%H:%M:%S') if temperature >= temperature_alert: Msg6 = str(d_date) + ' ' + str(d_time2) + ' ' + str(temperature) + " : Be careful! The Temperature exceeds " + str(temperature_alert) + " degrees" print(Msg6) client.publish(Topic,Msg6) if moisture <= moisture_alert: Msg6 = str(d_date) + ' ' + str(d_time2) + ' ' + str(moisture) + " : Need Water! The Ammount of waters is low " + str(moisture_alert) print(Msg6) client.publish(Topic,Msg6) if d <= distance_alert: Msg6 = str(d_date) + ' ' + str(d_time2) + ' ' +": Our lady HANA is coming ! Let's enterain her. But it might be Gin !!" print(Msg6) client.publish(Topic,Msg6) time.sleep(10)
def loop(): while True: analogVal = ADC0832.getResult() # print 'temp analog= %d C' % analogVal # Vr = 5 * float(analogVal) / 255 # Rt = 10000 * Vr / (5 - Vr) # temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25))) # temp = temp - 273.15 # temp = float("{0:.2f}".format(temp)) t = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if ARG_DISPLAY == 1: # print '%s Temperatur = %.2f C (Wartezeit: %ss)' % (t, temp, varWaitTime) print 'Rueckmeldung analoger Sensor: %s' % (analogVal) try: context = ssl._create_unverified_context() url = read_secret("json_push","url","/home/pi/ecg/") # print 'URL=%s' % url import json import urllib2 SENSOR_FQN = SENSOR_QUALIFIER + "." + SENSOR_TYPE data = { SENSOR_FQN: 1 } req = urllib2.Request(url) req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data), context=context)
def loop(): while True: t = ADC0832.getResult() vol = 5.0/255 * t vol = round(vol, 2) segment.numberDisplay_dec(vol) time.sleep(0.1)
def loop(): Rk = input("Input Known R-value: ") print print "Vc = ",Vc print "Rk = ",Rk while True: Rt = input("Input Unknown [Theoretical] R-value: ") print "Rt = ",Rt digOut = ADC0832.getResult() #Get reading from ADC Io = (Vc/Rk)*digOut / 255 #calculate amps output if 255 equals .5 A if Io > 0: Ra = ( Vc / Io ) - Rk #calculate resistance, subtract the 10 Ohm known resistor print 'Ra = ', Ra else: #avoid div by 0 error Ra = 1000 print "Ra = infinite" #print 'Io = ', Io print 'Do = ', digOut print '% = ', (Ra/Rt)*100,'%'
def loop(): while True: res = ADC0832.getResult() print 'res = %d' % res num = map(res, 0, 255, 0, 10) ledBarCtrl(num) time.sleep(0.2)
def loop(): while True: global digitalVal, analogVal analogVal = ADC0832.getResult(0) print 'Current analog value is %d' % analogVal GPIO.output(LedPin, GPIO.input(Flame_DO_Pin)) time.sleep(0.2)
def loop(): while True: analogVal = ADC.getResult(0) print 'adcval:', analogVal if analogVal > 0: print 'temp:', convert_to_temperature(analogVal) time.sleep(sleep_time)
def sensorData(): analogVal = ADC0832.getResult() Vr = 5 * float(analogVal) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1 / (((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25))) temp = temp - 273.15 return temp
def loop(): while True: res = ADC0832.getResult() print 'res = %d' % res num = map(res, 0, 255, 0, 10) ledBarCtrl(num) time.sleep(0.2)
def loop(): global camera while True: ## ADC / LDR Section ## res = ADC0832.getResult() - 80 if res < 0: res = 0 if res > 100: res = 100 print 'res = %d' % res time.sleep(0.2) ###### if (res == 0): camera.stop_preview else: global ppl_cnt camera.start_preview() print_msg() #print("LDR Value: %.3f" % float(ldr.value)) display(ppl_cnt) # tmp = int(raw_input('Please input a num(0~9999):')) # for i in range(500): # display(tmp) ppl_cnt += 1 time.sleep(2)
def UserPickPattern(): uArr = [] ADC0832.setup() for x in range(4): print"Move the red wire to your choice for the color in spot #",x+1," and press enter" raw_input() u = ADC0832.getResult() #Get reading from ADC if u > 248 and u < 252: uArr.append(1) elif u > 231 and u < 235: uArr.append(2) elif u > 126 and u < 130: uArr.append(3) elif u > 242 and u < 246: uArr.append(4) elif u > 211 and u < 215: uArr.append(5) elif u > 120 and u < 124: uArr.append(6) else: uArr.append(0) #print colored('0 ',colArr[uArr[0]]),colored('0 ',colArr[uArr[1]]),colored('0 ',colArr[uArr[2]]),colored('0 ',colArr[uArr[3]]) return uArr
def readval(): res = ADC0832.getResult() - 80 if res < 0: res = 0 if res > 100: res = 100 print('res = %d' % res) return res
def loop(): p = GPIO.PWM(LedPin, 1000) # Set PWM Frequence to 1000Hz p.start(0) while True: res = ADC0832.getResult() if res > 100: res = 100 p.ChangeDutyCycle(res) # Change the duty cycle according to res
def loop(): while True: res = ADC0832.getResult() - 80 if res < 0: res = 0 elif res > 100: res = 100 time.sleep(0.2)
def loop(): while True: analogVal = ADC.getResult(0) print 'adcval:', analogVal if analogVal > 200: beep() else: time.sleep(0.5)
def loop(): while True: analogVal = ADC.getResult(0) print 'adcval:', analogVal if analogVal > 200: beep() else: time.sleep(0.5)
def loop(): p = GPIO.PWM(LedPin, 1000) # Set PWM Frequence to 1000Hz p.start(0) while True: res = ADC0832.getResult() if res > 100: res = 100 p.ChangeDutyCycle(res) # Change the duty cycle according to res
def Light_loop(): while True: res = ADC0832.getResult(1) light= float((res*100)/255) print ('Brightness is: ' '%.0f' % light +'%') r.set('Brightness', light) time.sleep(2) return light
def loop(): while True: analogVal = ADC0832.getResult(0) print 'analog value is %d' % analogVal if (analogVal < thresholdVal): GPIO.output(LedPin, GPIO.HIGH) else: GPIO.output(LedPin, GPIO.LOW) time.sleep(0.2)
def main(): while True: res = ADC0832.getResult() - 80 if res < 0: res = 0 if res > 100: res = 100 print(f'light intensity: = {res}') time.sleep(0.2)
def ADCread(): """ This function reads the ADC and returns a string that is sutible for pumping directly into a message function for the LCD panel There are no arguments for this function """ result = ADC.getResult(ADC_CHANNEL) voltage = result * MAXVOLTAGE / MAXADCVALUE return "Current Voltage = \n %1.3f" % voltage
def loop(): while True: analogVal = ADC0832.getResult() Vr = 5 * float(analogVal) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25))) temp = temp - 273.15 print 'temperature = %d C' % temp time.sleep(0.2)
def loop(): while True: res = ADC0832.getResult() '''if res < 0: res = 0 if res > 100: res = 100''' print 'res = %d' % res time.sleep(0.2)
def Soil_loop(): while True: res = ADC0832.getResult() moisture = 255 - res pcntg = float((moisture * 100) / 255) print('moisture is: ' '%.0f' % pcntg + '%') # print ('analog value: %03d moisture is: %d' %(res, moisture)) time.sleep(2) return pcntg
def loop(): while True: analogVal = ADC0832.getResult() Vr = 5 * float(analogVal) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1 / (((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25))) temp = temp - 273.15 print 'temperature = %d C' % temp time.sleep(0.2)
def loop(): while True: res = ADC0832.getResult() if res < 0: res = 0 if res > 100: res = 100 print ('res = %d' % res) time.sleep(0.2)
def loop(): while True: res = ADC0832.getResult() if res < 0: res = 0 if res > 100: res = 100 print 'res = %d' % res time.sleep(0.2)
async def get_telemetry() -> str: # The dht call returns the temperature and the humidity, # we only want the temperature, so ignore the humidity result = DHT_SENSOR.read() temperature = result.temperature humidity = result.humidity light = ADC0832.getResult() - 80 light = min(max(light, 0), 100) print(f'light intensity: = {light}') # The temperature can come as 0, meaning you are reading # too fast, if so sleep for a second to ensure the next reading # is ready while True: if result.is_valid(): timestamp = datetime.strptime(datetime.now().strftime('%Y-%m-%d %H:%M %S'), '%Y-%m-%d %H:%M %S') print(timestamp, end='') print(" Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature, humidity)) print(timestamp, end='') print(f' light intensity: = {light}') mylcd.lcd_clear() msg1 = 'Temp: ' + str(round(temperature, 2)) + 'C' msg2 = 'Humidity: ' + str(round(humidity, 2)) + '%' mylcd.lcd_display_string(msg1,1) mylcd.lcd_display_string(msg2,2) break else: result = DHT_SENSOR.read() temperature = result.temperature humidity = result.humidity light = ADC0832.getResult() - 80 light = min(max(light, 0), 100) await asyncio.sleep(1) # Build a dictionary of data # The items in the dictionary need names that match the # telemetry values expected by IoT Central dict = { "Temperature" : temperature, # The temperature value "Humidity" : humidity, # The humidity value "Light" : light, # The light value } # Convert the dictionary to JSON return json.dumps(dict)
def readPhotoSens(chn=0): print "Reading light from channel: %d" % chn ADC0832.setup() photores = ADC0832.getResult(chn) - 80 if photores < 0: photores = 0 if photores > 100: photores = 100 print 'Relative light = %d' % photores time.sleep(0.2)
def loop(): while True: rainVal = ADC0832.getResult(0) print GPIO.input(RAIN) if GPIO.input(RAIN) == 0: print '***************' print '* !!RAINING!! *' print '***************' print '' print rainVal time.sleep(0.5)
def loop(): while True: analogVal = ADC.getResult(0) print "value =", analogVal illum = map(analogVal, 130, 255, 0, 100) if illum > 80: illum = 80 if illum < 0: illum = 0 p.ChangeDutyCycle(illum) print illum time.sleep(0.05)
def loop(): while True: screen.cursorTo(0, 0) screen.println(line) t = ADC0832.getResult() vol = 5.0/255 * t vol = round(vol, 2) vol = '%f' %vol vol = vol[:4] screen.cursorTo(1, 0) screen.println(' Voltage: ' + vol + 'V ') screen.clear() time.sleep(0.2)
def loop(): while True: tmp = ADC0832.getResult() # Get analog value from ADC0832 print tmp # Print analog value if tmp > TS : # Beep when read value greater than threshold print ' ****************' print ' * !! DANGER !! *' print ' ****************' print '' GPIO.output(BEEP, GPIO.HIGH) # (0, means detect danger gas) time.sleep(0.25) GPIO.output(BEEP, GPIO.LOW) time.sleep(0.25) else : time.sleep(0.5) # Else delay printing.
def loop(): while True: res = ADC0832.getResult() print 'res = %d' % res if res > 200: beep()
def loop(): while True: analogVal = ADC.getResult(0) distance = (6762 / (analogVal - 9)) - 4 print "distance:", distance time.sleep(0.4)
def loop(): while True: res = ADC0832.getResult() v = res * (3.3 / 255) print 'Current voltage: %.2f V' % v time.sleep(0.2)
def loop(): while True: res = ADC0832.getResult() print 'res = %d' %res time.sleep(0.1)
def loop(): while True: res = ADC0832.getResult() Gas_concentration = res print 'analog value: %03d Gas concentration: %d' %(res, Gas_concentration) time.sleep(0.1)
def push_message(self): analogVal = ADC.getResult(0) distance = (6762/(analogVal-9))-4 if distance > 0: self.write_message(str(distance)) tornado.ioloop.IOLoop.instance().add_timeout(datetime.timedelta(seconds=1), self.push_message)
def loop(): while True: res = ADC0832.getResult() level = 255 - res print 'analog value: %03d level: %d' %(res, level) time.sleep(0.1)
def loop(): while True: analogVal = ADC.getResult(0) print 'Current Voltage :', analogVal*(5.0/255), 'V' time.sleep(0.4)
def loop(): while True: res = ADC0832.getResult() vol = 5.0/255 * res print 'analog value: %03d || voltage: %.2fV' %(res, vol) time.sleep(0.2)
def loop(): while True: res0 = ADC0832.getResult(0) res1 = ADC0832.getResult(1) print "res0 = %d, res1 = %d" % (res0, res1) time.sleep(0.2)
def loop(): while True: res = ADC0832.getResult() moisture = 255 - res print 'analog value: %03d moisture: %d' %(res, moisture) time.sleep(0.1)
def micISR(ev=None): print "voice in..." analogVal = ADC0832.getResult() print 'res = %d' % res
def loop(): while True: analogVal = ADC.getResult(0) print 'adcval:', analogVal time.sleep(0.4)
def loop(): while True: res = ADC0832.getResult() volume = 255 - res print 'analog value: %03d volume: %d' %(res, volume) time.sleep(0.1)