Go Down

Topic: Save Servo Position on EEPROM (Read 699 times) previous topic - next topic

Eduort

Mar 23, 2013, 05:08 am Last Edit: Mar 23, 2013, 10:38 pm by Eduort Reason: 1
Hi, i made a program to move servos whit android, it works well, but now i want to save sequences of movements, for example, move servo 1 to 180°, move servo 2 to 100°, etc. only using the android phone, i have a idea but i dont know if it is good, this is the code to do the movements in manual form:
[c

Erdin

The EEPROM.write() writes only a byte.
http://arduino.cc/en/Reference/EEPROMWrite
But since a byte is 0...255 and the servo position is 0...180 it is okay.

Have you considered using a case statement ?

Code: [Select]

if (Serial.available() > 0) {         
  data = Serial.read();
}

switch (data) {
case 'X':
case 'x':
  EEPROM.write( 1, servo1 position);
  EEPROM.write( 2, servo2 position);         
  break;
case 'Y':
case 'y':
  pos1 = EEPROM.read(1);
  servo1.write(pos1);
  pos2 = EEPROM.read(2);
  servo1.write(pos2);         
  break;
default:
  break;
}

Go Up