Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int trigPin = 12;
- const int echoPin = 13;
- int leitura1;
- int leitura2;
- int resultado;
- int Leitura = 0;
- int Calculo;
- void setup() {
- Serial.begin(9600);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- }
- void loop() {
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- unsigned long vertical = pulseIn(echoPin, HIGH);
- int altura = vertical / 5.8;
- Serial.print("Distancia em milimetro: ");
- Serial.println(altura);
- if (Leitura == 0 )
- {
- Leitura = altura;
- }
- else
- {
- Calculo = altura - Leitura;
- Leitura = 0;
- }
- Serial.print("Diferença: ");
- Serial.println(altura);
- delay(5000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement