Advertisement
RuiViana

CalculaValor

May 30th, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. const int trigPin = 12;
  2. const int echoPin = 13;
  3.  
  4. int leitura1;
  5. int leitura2;
  6. int resultado;
  7.  
  8. int Leitura = 0;
  9. int Calculo;
  10.  
  11. void setup() {
  12.  
  13.   Serial.begin(9600);
  14.   pinMode(trigPin, OUTPUT);
  15.   pinMode(echoPin, INPUT);
  16. }
  17.  
  18. void loop() {
  19.  
  20.   digitalWrite(trigPin, LOW);
  21.   delayMicroseconds(2);
  22.   digitalWrite(trigPin, HIGH);
  23.   delayMicroseconds(10);
  24.   digitalWrite(trigPin, LOW);
  25.   unsigned long vertical = pulseIn(echoPin, HIGH);
  26.   int altura = vertical / 5.8;
  27.  
  28.   Serial.print("Distancia em milimetro: ");
  29.   Serial.println(altura);
  30.   if (Leitura == 0 )
  31.   {
  32.     Leitura = altura;
  33.   }
  34.   else
  35.   {
  36.     Calculo = altura - Leitura;
  37.     Leitura = 0;
  38.   }
  39.    Serial.print("Diferença: ");
  40.      Serial.println(altura);
  41.    delay(5000);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement