#include #include //this will be how we call the file throughout the code File myoPrj; void setup() { Serial.begin(9600); while(!Serial) { ; //will wait for USB to be connected } if(!SD.begin(10)) { Serial.println("Take a look at your SD port number please!"); return; } //create file for project, due to FAT16 file system, we must keep our file names 8(main name).3(extension) or fewer characters long //if the user already has a file named MyoPrj.txt in the active directory of the SD card... if SD.exists("MyoPrj.txt") { //begin loop to check for names which aren't taken yet for(int n = 1; n < 100) { //ex. if myoPrj1.txt is taken, the loop will now try myoPrj2.txt if SD.exists("MyoPrj" + n + ".txt") { n += 1; } //if we do find an open project name, go ahead and create the file else { myoPrj = SD.create("MyoPrj" + n + ".txt"); n = 101; } } //if there were no open names from myoPrj to myoPrj99, then we will need the user to remove some of the files from their SD card else { Serial.println("We can only have 100 projects on your SD card, it appears you have exceeded that amount. Please remove some of the files, then restart your arduino."); return; } } else { myoPrj = SD.create("MyoPrj.txt"); } } void loop() { //initialize vector of arrays that will handle the queue for our drawing head if it falls behind the user std::vector> myoVals; //we will add opening the file to the loop. this means that if the project is disturbed, or otherwise not allowed to complete, that the work completed by the draw bot can still be replicated SD.open(myoPrj, FILE_WRITE); /**begin your queue to get values from myo, place them into our vector we will then use our oldest (first) value in our vector to tell the motors where to go we then cut the oldest value of the vector into our file, so that we can duplicate the project if desired**/ plotting[2] = getCoordinates(); //send the motors our next position array motors(myoVals.front()); //write our line that was completed to our file myoPrj.println(myoVals.front()); //save the changes made to the file myoPrj.close(); //if the user has moved at least 1% of the canvas space between collection points, then we want to record their new position on the space (handled by the lua script to pass NULL if <1% changed) if(type(plotting) == int) { myoVals.push_back(plotting); } //remove the last command sent to the motors from our vector, which will then resize to move our queue along myoVals.erase(myoVals.begin()); }