Dateien nach "/" hochladen
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#include <string.h>
|
||||
#include <Servo.h>
|
||||
#define LED 13
|
||||
|
||||
#define PIN_OFFSET 2 //At which pin is the first connection, must be in row
|
||||
#define SERVO_NUM 7
|
||||
|
||||
int servoPos[SERVO_NUM] = {0};
|
||||
Servo ser[SERVO_NUM];
|
||||
|
||||
void setup() {
|
||||
//start serial connection
|
||||
Serial.begin(9600);
|
||||
pinMode(LED, OUTPUT);
|
||||
|
||||
for(int i = 0;i<SERVO_NUM;i++)
|
||||
{
|
||||
ser[i].attach(i + PIN_OFFSET);
|
||||
}
|
||||
Serial.println("START");
|
||||
}
|
||||
|
||||
void setAllZero()
|
||||
{
|
||||
for(int i = 0;i<SERVO_NUM;i++)
|
||||
{
|
||||
servoPos[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void moveServo()
|
||||
{
|
||||
for(int i = 0;i<SERVO_NUM;i++)
|
||||
{
|
||||
ser[i].write(servoPos[i]);
|
||||
delay(300);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printAll()
|
||||
{
|
||||
for(int i = 0;i<SERVO_NUM;i++)
|
||||
{
|
||||
Serial.println(servoPos[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
digitalWrite(LED, HIGH);
|
||||
// String str = Serial.readString();
|
||||
String str = "1456,677,123,456,789,999,111";
|
||||
str.trim();
|
||||
if(str[0] == '1')
|
||||
{
|
||||
Serial.println("OK1");
|
||||
str.remove(0,1);
|
||||
sscanf(str.c_str(),"%d,%d,%d,%d,%d,%d,%d",&servoPos[0],&servoPos[1],&servoPos[2],&servoPos[3],&servoPos[4],&servoPos[5],&servoPos[6]);
|
||||
printAll();
|
||||
moveServo();
|
||||
}
|
||||
else if (str[0] == '0')
|
||||
{
|
||||
Serial.println("OK0");
|
||||
setAllZero();
|
||||
moveServo();
|
||||
}
|
||||
delay(10);
|
||||
digitalWrite(LED, LOW);
|
||||
}
|
||||
Reference in New Issue
Block a user