NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

jmXCA:
Teckel, I've received a Due and downloaded NewPing (you asked earlier in the thread). The immediate issues are that it includes "avr/io.h" and "avr/interrupt.h", neither of which seem to have obvious counterparts for the ARM due.

With those headers missing, the following lines become issues:

C:\arduino-1.5.1r2\hardware\arduino\sam\libraries\NewPing\NewPing.cpp: In constructor 'NewPing::NewPing(uint8_t, uint8_t, int)':

SNIP

Ok, so in a pinch I quickly hacked this to work on the DUE (NO TIMERS YET). I'm new to Arduino so these changes probably have some side effect I'm not aware of (ie, I'm not sure why digitalWrite and pinMode functions weren't used in the first place - maybe just to avoid function calls?)
1) In NewPing.h:
-if'defd the AVR includes
#ifndef arm
#include <avr/io.h>
#include <avr/interrupt.h>
#ifndef arm

-added 2 members to NewPing class
uint8_t _triggerPin;
uint8_t _echoPin;

2) In NewPing.cpp:
-Added these 2 lines in the constructor
_triggerPin = trigger_pin;
_echoPin = echo_pin;

-Commented out the portModeRegister line

-Change any lines like "*_triggerMode |= _triggerBit; // Set trigger pin to output."
to: pinMode(_triggerPin,OUTPUT);

-And finally a new ping_trigger()
#ifdef arm
boolean NewPing::ping_trigger() {
#if DISABLE_ONE_PIN != true
pinMode(_triggerPin, OUTPUT);
#endif
digitalWrite(_triggerPin, LOW);
delayMicroseconds(4); // Wait for pin to go low, testing shows it needs 4uS to work every time.
digitalWrite(_triggerPin, HIGH);
delayMicroseconds(10); // Wait long enough for the sensor to realize the trigger pin is high. Sensor specs say to wait 10uS.
digitalWrite(_triggerPin, LOW);

#if DISABLE_ONE_PIN != true
pinMode(_triggerPin, INPUT);
#endif

_max_time = micros() + MAX_SENSOR_DELAY; // Set a timeout for the ping to trigger.
while ((digitalRead(_echoPin) == HIGH) && (micros() <= _max_time)) {}
while (!(digitalRead(_echoPin) == HIGH)) // Wait for ping to start.
if (micros() > _max_time) return false; // Something went wrong, abort.

_max_time = micros() + _maxEchoTime; // Ping started, set the timeout.
return true; // Ping started successfully.
}
#else
//old ping_trigger() goes here
#endif