I have develop a computerize loom from scratch, made with a Venetian blind and 16 servo motors that move the shafts to define the design of the weave.
you can see the Loom at
I am using the following sketch to move the servos using serial monitor and imputing by hand the values to move the servos
the following sample is for three servos but I will be using the same for 16 servos
#include <Servo.h>
String readString, servo1, servo2, servo3;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
Servo myservo3;
void setup() {
Serial.begin(9600);
myservo1.attach(1); //the pin for the servo control
myservo2.attach(2);
myservo3.attach(3);
}
void loop() {}
void serialEvent() {
while (Serial.available()) {
delay(2);
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0) {
Serial.println(readString); //see what was received
// expect a string like 07002100 containing the two servo positions
servo1 = readString.substring(0, 2); //get the first two characters
servo2 = readString.substring(2, 4); //get the next two characters
servo3 = readString.substring(4, 6);
Serial.println(servo1); //print ot serial monitor to see results
Serial.println(servo2);
Serial.println(servo3);
int n1; //declare as number
int n2;
int n3;
char carray1[6]; //magic needed to convert string to a number
servo1.toCharArray(carray1, sizeof(carray1));
n1 = atoi(carray1);
char carray2[6];
servo2.toCharArray(carray2, sizeof(carray2));
n2 = atoi(carray2);
char carray3[6];
servo3.toCharArray(carray3, sizeof(carray3));
n3 = atoi(carray3);
myservo1.write(n1); //set servo position
myservo2.write(n2);
myservo3.write(n3);
readString=""; will read the next string
}
}
So if I imput and enter in the serial monitor;
000000 the three motors will move to position 0 degrees
if I imput:
001500 the second motor will rotate 15 degrees the other 2 will stay at 0
One of the more simple weaves it is called "plain width" and will need to repeat only two sequences to be completed:
sequence 1; 001500
sequence 2: 150015
Question?
How and where can I store these two sequences so when I press enter in the serial monitor takes and executes the first sequence only, if I press again enter will take and execute the second sequence, and if I press enter again would go backwards and execute the first sequence, and so on.
I have been looking at serial monitor tutorials and how to read text files and upload them to the Arduino as I will be working with more complicated and long sequences of numbers.
I come from a design background and, to be honest, I am finding it difficult to understand and apply some of the codes that I have seen browsing the subject. I do not know where the sequences could be store, how to store them in the buffer, how to let the serial monitor know the number of characters that i want to upload every time I press enter, how can I go forward or backwards through the sequences
I will really appreciate some help
Thanks