Sfoglia il codice sorgente

Merge testing into master

subDesTagesMitExtraKaese 3 anni fa
parent
commit
f44e1f603c
2 ha cambiato i file con 17 aggiunte e 16 eliminazioni
  1. 17 16
      arduino/src/ultrasonic.cpp
  2. BIN
      ultrasound-tests.ods

+ 17 - 16
arduino/src/ultrasonic.cpp

@@ -39,23 +39,24 @@ void us_transmit() {
   //disable pin interrupts
   EIMSK = 0;
 
-  pinMode(US_RX_0_PIN, OUTPUT);
-  pinMode(US_RX_1_PIN, OUTPUT);
-  pinMode(US_TX_0_PIN, OUTPUT);
-  digitalWrite(US_RX_0_PIN, LOW);
-  digitalWrite(US_RX_1_PIN, LOW);
-  digitalWrite(US_TX_0_PIN, LOW);
+  //set pin 2, 3 and 4 to output
+  DDRD  |= 0b00011100;
+  PORTD &= 0b11100011;
+
   delayMicroseconds(2);
-  digitalWrite(US_RX_0_PIN, HIGH);
-  digitalWrite(US_RX_1_PIN, HIGH);
-  digitalWrite(US_TX_0_PIN, HIGH);
+
+  //pull pin 2, 3 and 4 to 5V
+  //doing this seems to lead to power supply issues and the serial interface stopps working
+  //further testing needed!
+  PORTD |= 0b00011100;
+
   delayMicroseconds(5);
-  digitalWrite(US_RX_0_PIN, LOW);
-  digitalWrite(US_RX_1_PIN, LOW);
-  digitalWrite(US_TX_0_PIN, LOW);
-  pinMode(US_RX_0_PIN, INPUT);
-  pinMode(US_RX_1_PIN, INPUT);
-  pinMode(US_TX_0_PIN, INPUT);
+
+  //pull pin 2, 3 and 4 to GND
+  PORTD &= 0b11100011;
+
+  //set pin 2, 3 and 4 back to input
+  DDRD  &= 0b11100011;
 
   //enable pin interrupts
   EIMSK = _BV(INT1) | _BV(INT0);
@@ -72,4 +73,4 @@ long us_get_duration(byte sensor) {
   } else {
     return -(F_CPU / 1000000);
   }
-}
+}

BIN
ultrasound-tests.ods