Teensy 2019: read SSC-32 style servo commands, first step to replacing the SSC-32
From the Arduino sketchbook.
This commit is contained in:
1 parent
413f52c008
commit
2373167785
1 file changed
+41
@@ -0,0 +1,41 @@
|
||||
float servos[18];
|
||||
|
||||
void setup() {
|
||||
Serial.println("servo serial control");
|
||||
}
|
||||
|
||||
|
||||
void loop() // "1_180 2_90"
|
||||
{
|
||||
if (Serial.available())
|
||||
{
|
||||
String data = Serial.readStringUntil('\r');
|
||||
int maxIndex = data.length() - 1;
|
||||
int index = 0;
|
||||
int next_index;
|
||||
String data_word;
|
||||
String channel;
|
||||
String angle;
|
||||
do {
|
||||
next_index = data.indexOf(',', index);
|
||||
|
||||
data_word = data.substring(index, next_index);
|
||||
channel = data_word.substring(0, data_word.indexOf('_'));
|
||||
angle = data_word.substring(data_word.indexOf('_') + 1);
|
||||
|
||||
servos[channel.toInt()] = angle.toFloat();
|
||||
|
||||
index = next_index + 1;
|
||||
} while ((next_index != -1) && (next_index < maxIndex));
|
||||
|
||||
Serial.println("Output line: ");
|
||||
for (int i = 0; i < 18; i++)
|
||||
{
|
||||
Serial.print(i);
|
||||
Serial.print(", ");
|
||||
Serial.print(servos[i]);
|
||||
Serial.println("");
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user