[Solved] How can I use the Arduino microseconds delay of SPC-560P?
gl2 2015-06-29
Posted on June 29, 2015 at 13:09
I have this sensor HY-SRF05 with 5 pins. In Arduino using the function delayMicroseconds () to manage the operation of the sensor so:
Arduino code:
/*
Tested with HY-SRF05, HC-SR04
Assuming a room temp of 20 degrees centigrade
The circuit:
* VVC connection of the sensor attached to +5V
* GND connection of the sensor attached to ground
* TRIG connection of the sensor attached to digital pin 12
* ECHO connection of the sensor attached to digital pin 13
*/
const
int
TRIG_PIN = 12;
const
int
ECHO_PIN = 13;
void
setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(TRIG_PIN,OUTPUT);
pinMode(ECHO_PIN,INPUT);
}
void
loop()
{
long
duration, distanceCm, distanceIn;
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN,HIGH);
// convert the time into a distance
distanceCm = duration / 1 / 2 ;
distanceIn = duration / 74 / 2;
if
(distanceCm<= 0){
Serial.println(
'Out of range'
);
}
else
{
Serial.print(distanceIn);
Serial.print(
'in, '
);
Serial.print(distanceCm);
Serial.print(
'cm'
);
Serial.println();
}
delay(1000);
}
Of SPC560P how can I do? The board does not handle microseconds.
Best regards
Gianluca.
------------------------------ Posted on July 01, 2015 at 12:05
Ok, the function osalThreadSleepMicroseconds it works.
Thanks.
Best regards
Gianluca