RuiViana

Teste_if

Aug 21st, 2016
153
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <NewPing.h>
  2. #define TRIGGER_PIN 5
  3. #define ECHO_PIN 6
  4. #define MAX_DISTANCE 200
  5.  
  6. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.   Serial.println("Lendo... ");
  11. }
  12. void loop()
  13. {
  14.   delay(5000);                        // Espera 5 seg entre os pings
  15.   unsigned int u = sonar.ping();      // Envia o ping.
  16.   Serial.print("Ping: ");
  17.   Serial.print(sonar.convert_cm(u));  //Converte (se =0 esta fora do alcance ou nao recebeu o echo)
  18.   Serial.println("cm");
  19.  
  20.   Serial.println("u " + String(u));  // Qual valres imprime aqui?
  21.  
  22.   if (u > 20)
  23.   {
  24.     Serial.println("sim");
  25.   } else
  26.   {
  27.     Serial.println("nao");
  28.   }
  29. }
RAW Paste Data