/* * Author: Pratesh Kumar Reddy * Copyright: Free to use with attributes / /*This code will read the analog sensor values from the four analog i/o pins and based up on that it will take decision on park lot occupancy.Then it will write the data onto a file "parklot1.txt" with the following data packet format (mother_id)$(sensor_id)$(sensor_stat)$(analog_input_value)*/ #include #include #include #include "mraa.h" int mother_id=1,sensor_id,sensor_stat[4]; uint16_t adc_value[4],threshold=1500; int i; FILE *fp; int main () { mraa_aio_context aio0,aio1,aio2,aio3; aio0=mraa_aio_init(0); aio1=mraa_aio_init(1); aio2=mraa_aio_init(2); aio3=mraa_aio_init(3); fp =fopen("/iot/parklot1.txt","w"); adc_value[0]=mraa_aio_read(aio0); //printf("%d",adc_value[0]); adc_value[1]=mraa_aio_read(aio1); //printf("%d",adc_value[1]); adc_value[2]=mraa_aio_read(aio2); //printf("%d",adc_value[2]); adc_value[3]=mraa_aio_read(aio3); //printf("%d",adc_value[3]); for(i=0;i<3;i++) { if(adc_value[i] < threshold && sensor_stat[i] ==0) { sensor_stat[i]=1; } else if(adc_value[i] > threshold && sensor_stat[i] ==1) { sensor_stat[i]=0; } } fprintf(fp,"%d$%d$%d$%d\n",mother_id,0,sensor_stat[0],adc_value[0]); fprintf(fp,"%d$%d$%d$%d\n",mother_id,1,sensor_stat[1],adc_value[1]); fprintf(fp,"%d$%d$%d$%d\n",mother_id,2,sensor_stat[2],adc_value[2]); fprintf(fp,"%d$%d$%d$%d\n",mother_id,3,sensor_stat[3],adc_value[3]); fclose(fp); return 0; }