abdelah el fahim
/
SHT21_ncleee
SHT21 CODE WITH TIMER and interruption
Fork of SHT21_ncleee by
main.cpp
- Committer:
- abdelah
- Date:
- 2018-01-24
- Revision:
- 4:2daacfab92a8
File content as of revision 4:2daacfab92a8:
#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();} } }