/* the steppermotor runs fine and round when I
* do not use sonar and/or pulsein lines.
* when I use sonar and/or pulsein code, then
* every 5 seconds, motor make a "clack"
* sonarping AND pulsein both have probably
* "delay-problems" in loop-section with steppermotor
* driver - because? Too long sonar/pulsein responses?
*/
#include <NewPing.h> // newping library
#include <dmtimer.h> // dmtimer library
#define trigPin 1 // trigPin: pwm 1
#define echoPin 2 // echoPin: pwm 2
#define Switch 3 // Switch: pwm 3
#define DistanceMax 300
int distance;
unsigned int RC_Channel
NewPing sonar(trigPin, echoPin, DistanceMax);
DMTimer myTimer(5000000); // 5000000 = 5 seconds
// ::
// steppermotor code
// ::
void setup(){
pinMode(Switch, INPUT_PULLUP);
// ::
// steppermotor code
// ::
}
void loop(){
if (myTimer.isTimeReached()){ // wait between sonar pings and pulsein checking
distance = sonar.ping_cm();
RC_Channel = pulseIn(Switch, HIGH, 25000);
}
// ::
// steppermotor code
// ::
}