Answer the question
In order to leave comments, you need to log in
Read variable values from file?
On the SD card, a file that contains strings consisting of two three-digit numbers. More or less like this:
123 567 137 457 265 356 ...
#define N_SERVO 2
int PIN_SERVO[N_SERVO] = {2,3};
Servo servo[N_SERVO];
for (int i = 0; i < N_SERVO; i++)
{
servo[i].attach(PIN_SERVO[i]));
}
data = SD.open("1.txt", FILE_READ);
while (data.available())
{
for (int i = 0; i < N_SERVO; i++)
{
servo[i].write(data.parseInt( ));
}
}
data.close();
Answer the question
In order to leave comments, you need to log in
Figured it out myself. The habit of solving problems in a general way failed...
I threw out all the for loops. In the while loop:
while (myFile.available()) {
int i=myFile.parseInt();
int j=myFile.parseInt();
int val = ((i*0.4905) - 55.0224) + 0.51;
myservo.write(val);
delay (20);
int val1 = ((j*0.4905) - 55.0224) + 0.51;
myservo1.write(val1);
delay (20);
}
Did not work with sd but judging by the documentation ( https://www.arduino.cc/en/Tutorial/ReadWrite) you need to do data.read()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question