From c5cbba64af86adb226e433ba96da5c0a1984a68d Mon Sep 17 00:00:00 2001 From: Nick Gnoevoj Date: Thu, 23 Jan 2020 00:42:39 +0100 Subject: [PATCH] Removed timer. --- .../Temperatur_und_Abstandsmessung.ino | 77 +++++++++---------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/Code/Temperatur_und_Abstandsmesung/Temperatur_und_Abstandsmessung.ino b/Code/Temperatur_und_Abstandsmesung/Temperatur_und_Abstandsmessung.ino index 60cd80e..a468ae7 100644 --- a/Code/Temperatur_und_Abstandsmesung/Temperatur_und_Abstandsmessung.ino +++ b/Code/Temperatur_und_Abstandsmesung/Temperatur_und_Abstandsmessung.ino @@ -1,47 +1,51 @@ #include -#define trig PD3 -#define echo PD4 +#define trig 3 +#define echo 4 long distance = 0; +long echotime; +long timer = 0; int count = 0; -// ISR For Timer -ISR(TIMER0_COMPA_vect){ - - //set count depending on tcnt0 and the prescaler - if(count == 96){ - count = 0; - TCNT0 = 0; - - digitalWrite(trig, HIGH); - // ... wait for 10 µs ... - - delayMicroseconds(10); - // ... put the trigger down ... - digitalWrite(trig, LOW); - - PCICR |= 0b00000100; - PCMSK2 |= 0b00010000; - - } else { - count++; - } -} //ISR for PCINT20 ISR(PCINT2_vect) { - distance = pulseIn(echo, HIGH); + cli(); + distance = pulseIn(echo, HIGH); PCICR &= ~0b00000100; PCMSK2 &= ~0b00010000; delayMicroseconds(10); + } long calculateDistance(){ return (long) (((float) distance/ 58.0)); } +void measureDistance(){ + Serial.println("Measuring"); + + PORTD |= (1<= 100){ + measureDistance(); + timer = millis(); + } + Serial.print("Temperatur: "); Serial.println(dallas(2, 0)); - + Serial.print("Distanz: "); Serial.print(calculateDistance()); Serial.println("cm");