Advertisement
Guest User

Uso pulseIn

a guest
Jun 17th, 2010
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. int input = 7;
  2. unsigned long duracion,actual;
  3. float temp;
  4.  
  5. void setup() {
  6. Serial.begin(9600);
  7. }
  8.  
  9. void loop() {
  10. duracion = 0;                       //Reseteamos los valores
  11. for (int x=0; x<30; x++){
  12.  actual = pulseIn(input, HIGH);     //Medimos el tiempo en ON de la señal
  13.  if (actual > duracion){
  14. duracion = actual;                  //Tomamos el mayor valor de 30 muestras
  15. }
  16. delay(30);                          //Hacemos una pausa
  17. }
  18. temp = 2 * duracion;                //Calculamos la temperatura con el periodo de la señal
  19. temp = 225 - temp/5;
  20. Serial.println(temp);
  21. delay(300);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement