Hallo
Ich kenne die Steuerplatine nicht, aber “HB” followed by 4 bytes of data sets the mode (0-2) and power (0-255) of each “H” bridge.würde ich nicht so interpretieren. Mit 4 Bytes sind vermutlich nicht 4 ASCII-Ziffern gemeint sóndern 4 Werte von 0 bis 255:
HBCHR(0-2)CHR(0-255)chr(0-2)chr(0-255)
wobei CHR(x) für den Wert steht, den du sendest. 'A' ist 65, 'B' ist 66...
Gruß
mic
So wirds auch im Beispiel beschrieben:
Code:
// HB = "H" bridge data - next 4 bytes will be:
// left motor mode 0-2
// left motor PWM 0-255
// right motor mode 0-2
// right motor PWM 0-255
Code:
// --------------------------------------------------------- Code to drive dual "H" bridges --------------------------------------
if (Charged==1) // Only power motors if battery voltage is good
{
if ((millis()-leftoverload)>overloadtime)
{
switch (Leftmode) // if left motor has not overloaded recently
{
case 2: // left motor forward
analogWrite(LmotorA,0);
analogWrite(LmotorB,LeftPWM);
break;
case 1: // left motor brake
analogWrite(LmotorA,LeftPWM);
analogWrite(LmotorB,LeftPWM);
break;
case 0: // left motor reverse
analogWrite(LmotorA,LeftPWM);
analogWrite(LmotorB,0);
break;
}
}
if ((millis()-rightoverload)>overloadtime)
{
switch (Rightmode) // if right motor has not overloaded recently
{
case 2: // right motor forward
analogWrite(RmotorA,0);
analogWrite(RmotorB,RightPWM);
break;
case 1: // right motor brake
analogWrite(RmotorA,RightPWM);
analogWrite(RmotorB,RightPWM);
break;
case 0: // right motor reverse
analogWrite(RmotorA,RightPWM);
analogWrite(RmotorB,0);
break;
}
}
}
else // Battery is flat
{
analogWrite (LmotorA,0); // turn off motors
analogWrite (LmotorB,0); // turn off motors
analogWrite (RmotorA,0); // turn off motors
analogWrite (RmotorB,0); // turn off motors
}
}
}
Lesezeichen