I wish.doc-helmut wrote:but thx anyway - you seem to have a very good understanding of all about IIC reading and writing
One thing I don't get is what are all those data[1] to data[7] values represent...
Code: Select all
ReadSensorUSEx(port, data);
I wish.doc-helmut wrote:but thx anyway - you seem to have a very good understanding of all about IIC reading and writing
Code: Select all
ReadSensorUSEx(port, data);
Code: Select all
// 1 US sensor at port 0=S1
// 1 US sensor at port 1=S2
#define printf2( _x, _y, _format1, _format2, _value1, _value2) { \
string sval1 = FormatNum(_format1, _value1); \
string sval2 = FormatNum(_format2, _value2); \
string s =sval1+sval2; \
TextOut(_x, _y, s); \
}
void USSingleShot(byte port, int &echo)
{
byte ping_cmnd[] = {0x2, 0x41, 0x1}; // sensor one-shot-mode command
byte register_select[] = {0x2, 0x42}; // sensor data register
byte data_size=4;
byte data[4]; // =data_size, up to 4 echoes
I2CWrite(port, 0, ping_cmnd);
Wait(40); // waiting time shortened!
if (I2CBytes(port, register_select, data_size, data)) {
echo=data[0]; } // 1st echo
}
task main()
{
int
e_left, // US-Echodaten von US Sensor an port 0 (S1)
e_right; // US-Echodaten von US Sensor an port 1 (S2)
SetSensorLowspeed(0);
SetSensorLowspeed(1);
while(true)
{
USSingleShot(0, e_left);
Wait(40);
USSingleShot(1, e_right);
printf2( 0, 0, "%4d", " %4d", e_left, e_right);
Wait(40);
}
}
Users browsing this forum: No registered users and 7 guests