Hardware Reference
In-Depth Information
130 for (;;) {
131 if ( setjmp(timeout_exit) ) { /
Timeouts go here
/
132 if ( is_signaled ) /
SIGINT?
/
133 break; /
Yes, then exit loop
/
134 fprintf(stderr," (Timeout # %d)\
n",++timeouts);
135 wait = 5;
136 } else wait = 2;
137
138 wait_until_high(); /
Wait GPIO line to go high
/
139 timed_wait(wait,0,0); /
Pause for sensor ready
/
140
141 gpio_config(gpio_dht11,Output); /
Output mode
/
142 gpio_write(gpio_dht11,0); /
Bring line low
/
143 timed_wait(0,30000,0); /
Hold low min of 18ms
/
144 gpio_write(gpio_dht11,1); /
Bring line high
/
145
146 gpio_config(gpio_dht11,Input); /
Input mode
/
147 wait_until_low() /
Wait for low signal
/
148 wait_until_high(); /
Wait for return to high
/
149
150 if ( rsensor(&relhumidity,& celsius) )
151 printf("RH %d%% Temp %d C Reading %d\n",
relhumidity, celsius,++readings);
152 else fprintf(stderr," (Error # %d)\n",++errors);
153 }
154
155 gpio_config(gpio_dht11,Input); /
Set pin to input mode
/
156
157 puts("\ nProgram exited due to SIGINT: \n");
158 printf("Last Read: RH %d%% Temp %d C, %d errors, "
"%d timeouts, %d readings \n",
159 relhumidity, celsius, errors, timeouts, readings);
160 return 0;
161 }
162
163 /
End dht11.c
/
Search WWH ::




Custom Search