def change_time(number): print("Sending message") grovepi.fourDigit_segment(SENSOR_ID, 0, 0x9) # 15 = F grovepi.fourDigit_segment(SENSOR_ID, 1, 63) # 15 = F grovepi.fourDigit_segment(SENSOR_ID, 2, 63) # 15 = F grovepi.fourDigit_segment(SENSOR_ID, 3, 56) # 15 = F print("Sleeping for 2 seconds") time.sleep(2) print("Sending message") grovepi.fourDigit_number(SENSOR_ID, int(number), LEADING_ZERO) return "I changed the display! {}".format(number)
grovepi.fourDigit_init(display) time.sleep(.5) print ("Test 2) Set brightness") for i in range(0,8): grovepi.fourDigit_brightness(display,i) time.sleep(.2) time.sleep(.3) # set to lowest brightness level grovepi.fourDigit_brightness(display,0) time.sleep(.5) print ("Test 3) Set number without leading zeros") leading_zero = 0 grovepi.fourDigit_number(display,1,leading_zero) time.sleep(.5) grovepi.fourDigit_number(display,12,leading_zero) time.sleep(.5) grovepi.fourDigit_number(display,123,leading_zero) time.sleep(.5) grovepi.fourDigit_number(display,1234,leading_zero) time.sleep(.5) print ("Test 4) Set number with leading zeros") leading_zero = 1 grovepi.fourDigit_number(display,5,leading_zero) time.sleep(.5) grovepi.fourDigit_number(display,56,leading_zero) time.sleep(.5) grovepi.fourDigit_number(display,567,leading_zero)
# Connect the Grove 4 Digit Display to digital port D5 # CLK,DIO,VCC,GND display = 5 grovepi.pinMode(display,"OUTPUT") # If you have an analog sensor connect it to A0 so you can monitor it below sensor = 0 grovepi.pinMode(sensor,"INPUT") time.sleep(.5) while True: try: grovepi.fourDigit_brightness(display,2) #seconds = 10 #grovepi.fourDigit_monitor(display,sensor,seconds) temp = round(grovepi.temp(sensor,'1.2'), 2) grovepi.fourDigit_init(display) grovepi.fourDigit_number(display,int(temp * 100),0) #print(temp.__class__) #print("temp =", temp) time.sleep(.5) except KeyboardInterrupt: grovepi.fourDigit_off(display) break except IOError: print ("Error")
def display(self, pos, value): grovepi.fourDigit_number(self.__pin, value, pos)
def showDisplayNumberEI(): global events, display grovepi.fourDigit_number(display, events.getNumberDetectedEI(), 1)
M = '%02d' % mydate.minute S = '%02d' % mydate.second t = '%02d' % temp h = '%02d' % hum V = str(sensor_value) R = '%02d' % resistance d = str(distance) digitalWrite(led,0) # Send HIGH to switch on LED time.sleep(.1) digitalWrite(led,1) # Send LOW to switch on LED time.sleep(.1) digitalWrite(led,0) # Send HIGH to switch on LED #sys.stdout = open('file5', 'a+') #print A," ",D," ",O," ",Y," ",H,":",M,":",S,"\t",temp,"\t",hum, "\t",V,"\t",R #setRGB(random.randint(0,255),random.randint(0,255),random.randint(0,255)) #setText(H + ":" + M + ":" + S + "\n" + A + " " + D + " " + O + " " + Y + " " + Z) #time.sleep(5) setRGB(random.randint(0,255),random.randint(0,255),random.randint(0,255)) setText("tmp " + t + "C " + "hum " + h + "%" + "\n" + "lig " + V + "u " + "dis " + d + "u") grovepi.fourDigit_number(display,L,leading_zero) time.sleep(.1) except (IOError,TypeError) as e: print "Error"
import time import grovepi display = 5 sensor = 3 leading_zero = 0 grovepi.fourDigit_number(display, 5, leading_zero) while True: list = grovepi.dht(3, 0) grovepi.fourDigit_number(display, int(list[0]), 1) time.sleep(3)
def main(): timer = -1 #Calcul nombre de lignes dans la table log while(True): try: # orientation: (0 = red to green, 1 = green to red) grovepi.ledBar_init(ledbar, 0) time.sleep(.5) grovepi.fourDigit_init(display) time.sleep(.5) sensor_value = grovepi.analogRead(air_sensor) val = str(sensor_value) horloge= datetime.datetime.now().strftime("%H:%M:%S") print ("Qualite de l air : " + val) time.sleep(1) [temp,humidity] = grovepi.dht(sensor,blue) if math.isnan(temp) == False and math.isnan(humidity) == False: timer = timer+1 print ("timer" + str(timer)) print("temp = %.02f C humidity =%.02f%%"%(temp,humidity)) setText("Temp : " + str(temp) + " Hum : " + str(humidity)+"%") if (timer%12==0): print("La temperature de la piece a " +str(horloge) + " est de : " + str(temp) + " C") api.PostUpdate("La temperature de la piece a " +str(horloge) + " est de : " + str(temp) + " C") else: pass if sensor_value > 130: setText("Temp : " + str(temp) + " Hum : " + str(humidity)+"%") setRGB(247,35,12) digitalWrite(ledvert,0) digitalWrite(ledrouge,1) time.sleep(.5) digitalWrite(ledrouge,0) grovepi.ledBar_setLevel(ledbar, 2) time.sleep(.5) elif sensor_value > 70: setText("Temp : " + str(temp) + " Hum : " + str(humidity)+"%") setRGB(255,215,0) digitalWrite(ledvert,0) digitalWrite(ledrouge,1) time.sleep(2) digitalWrite(ledrouge,0) grovepi.ledBar_setLevel(ledbar, 5) time.sleep(.5) else: setText("Temp : " + str(temp) + " Hum : " + str(humidity)+"%") setRGB(15,157,232) digitalWrite(ledrouge,0) digitalWrite(ledvert,1) time.sleep(1) grovepi.ledBar_setLevel(ledbar, 11) time.sleep(.5) curs.execute("SELECT COUNT(*) FROM log2") lignes=curs.fetchone() nblignes=lignes[0] compteur = nblignes print("Il y a " + str(compteur) + " personnes " ) leading_zero = 0 grovepi.fourDigit_number(display,compteur,leading_zero) time.sleep(.5) if (compteur !=0): digitalWrite(lumiere,1) else: digitalWrite(lumiere,0) f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if ( f.verifyPassword() == False ): raise ValueError('The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) #while ( f.readImage() == False ): # pass try: key= f.readImage() today= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") rdy = datetime.datetime.now().strftime("%b %d %Y") #str(today) clock= datetime.datetime.now().strftime("%H:%M:%S") if (key == False): pass if (key != False): curs.execute("SELECT COUNT(*) FROM log2") lignes=curs.fetchone() nblignes=lignes[0] print(nblignes) ## Converts read image to characteristics and stores it in charbuffer 1 f.convertImage(0x01) ## Searchs template result = f.searchTemplate() positionNumber = result[0] curs.execute("SELECT statut FROM user WHERE id_finger= ('%s')" %positionNumber) statut = curs.fetchone() stat=statut[0] print("Vous etes un : " + str(stat)) salle ="T229" if (stat == "PROF"): today= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") str(today) print(today) curs.execute("SELECT nomP FROM prof WHERE id_finger = ('%s')" %positionNumber) nomP= curs.fetchone() nomtemp = nomP[0] print( nomtemp) curs.execute("SELECT numP FROM prof WHERE id_finger = ('%s')" %positionNumber) numP= curs.fetchone() numtemp = numP[0] print( numtemp) sql=("SELECT COUNT(*) FROM log2 WHERE(nom='%s')" %(nomtemp)) curs.execute(sql) nboccu=curs.fetchone() noccu=nboccu[0] if (noccu==0): curs.execute("INSERT INTO log2 (nom, date, salle, num, statut) VALUES ('%s', '%s', '%s','%s','%s')" %(nomtemp, today, salle, numtemp, stat)) db.commit() else: curs.execute("DELETE FROM log2 WHERE num = ('%s')" %numtemp) db.commit() else: today= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") str(today) print(today) curs.execute("SELECT nomE FROM eleve WHERE id_finger = ('%s')" %positionNumber) nomE= curs.fetchone() nomtemp = nomE[0] print( numtemp) sql=("SELECT COUNT(*) FROM log2 WHERE(nom='%s')" %(nomtemp)) curs.execute(sql) nboccu=curs.fetchone() noccu=nboccu[0] if (noccu==0): curs.execute("INSERT INTO log2 (nom, date, salle, num, statut) VALUES ('%s', '%s', '%s','%s','%s')" %(nomtemp, today, salle, numtemp, stat)) db.commit() else: curs.execute("DELETE FROM log2 WHERE num = ('%s')" %numtemp) db.commit() except KeyboardInterrupt: digitalWrite(lumiere,0) digitalWrite(ledrouge,0) digitalWrite(lumiere,0) digitalWrite(ledvert,0) quit(1) except Exception as e: print("Empreinte non reconnue , reesayez") print("Duplicate Tweet or Twitter Refusal: {}".format(e))
M = '%02d' % mydate.minute S = '%02d' % mydate.second t = '%02d' % temp h = '%02d' % hum V = str(sensor_value) R = '%02d' % resistance d = str(distance) digitalWrite(led, 0) # Send HIGH to switch on LED time.sleep(.1) digitalWrite(led, 1) # Send LOW to switch on LED time.sleep(.1) digitalWrite(led, 0) # Send HIGH to switch on LED #sys.stdout = open('file5', 'a+') #print A," ",D," ",O," ",Y," ",H,":",M,":",S,"\t",temp,"\t",hum, "\t",V,"\t",R #setRGB(random.randint(0,255),random.randint(0,255),random.randint(0,255)) #setText(H + ":" + M + ":" + S + "\n" + A + " " + D + " " + O + " " + Y + " " + Z) #time.sleep(5) setRGB(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) setText("tmp " + t + "C " + "hum " + h + "%" + "\n" + "lig " + V + "u " + "dis " + d + "u") grovepi.fourDigit_number(display, L, leading_zero) time.sleep(.1) except (IOError, TypeError) as e: print "Error"
def setNumber(self, value=0, leading_zero=1): """ display a number on 4 digit display by default display number 0 without leading zeroes """ grovepi.fourDigit_number(self.display, value, leading_zero)
def setValue(self, value, leadingZero): print("set value to", value, " with leadingZero = ", leadingZero) grovepi.fourDigit_number(self.port, value, leadingZero) return