SHT21 CODE WITH TIMER and interruption

Dependencies:   mbed

Fork of SHT21_ncleee by Graeme Coapes

Revision:
4:2daacfab92a8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 24 09:02:31 2018 +0000
@@ -0,0 +1,86 @@
+#include "mbed.h"
+#include "SHT21_ncleee.h"
+        
+DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX);
+I2C i2c(I2C_SDA, I2C_SCL);
+SHT21 sht(&i2c);
+InterruptIn button(USER_BUTTON);
+
+bool ISR_Flag=true;
+       
+Ticker timer;
+
+int indice=0; 
+int tab[10][2];
+int test;
+
+char buffer[32];
+
+void pressed()
+{
+ test=1;
+}
+void released()
+{
+ test=0;
+}
+ 
+void bla()
+ 
+{
+    
+//pc.printf("Hello World...\n\tTesting humidity Sensor\n"); 
+
+time_t seconds = time(NULL);        
+int humidity = sht.readHumidity();
+int temperature = sht.readTemp();
+
+tab[indice][0] = humidity; 
+tab[indice][1] = temperature;
+     
+/*pc.printf(" hum is: %d \n", humidity);
+pc.printf(" temp is: %d \n", temperature);*/
+
+if(indice > 9) { 
+
+for(int i = 0; i<10; i++) {
+
+
+//pc.printf("%d / %d / \n", tab[i][0], tab[i][1]);
+    if(test==1){
+    indice = 0;
+    } 
+} 
+} else {
+pc.printf(" indice= %d \n", indice);    
+pc.printf(" humidity=  %d \n", humidity);
+pc.printf(" temperature=  %d \n", temperature);
+strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
+printf("Heure = %s", buffer);
+indice = indice +1; 
+} 
+            
+ISR_Flag=false;
+}
+
+void isr2(void) 
+{
+    ISR_Flag=true;
+}   
+
+//}       
+        
+        
+int main() 
+{
+    button.fall(&pressed);
+    button.rise(&released);
+      timer.attach(&isr2,3);
+    //set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC 
+      while(1)
+     {
+        if(ISR_Flag==true){bla();}  
+     }    
+}
+             
\ No newline at end of file