/* This code was written by Sam Nissim with help from Austin Gager and Earl Wood to control a spin-coater. A Spin coater is a device that rotates a small disk attached to a motor at high speed, causing a solution to evenly distribute over a substrate. (To be fair, we borrowed heavily from public domain code from adafruit) Last update: 3/24/2015 */ #include "Adafruit_NECremote.h" // include remote library // Connect a 38KHz remote control sensor to the pin below #define IRpin 49 Adafruit_NECremote remote(IRpin); // include the library code for the LCD screen: #include // include the library for the motor shield: #include #include #include "utility/Adafruit_PWMServoDriver.h" // Create the motor shield object with the default I2C address Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Or, create it with a different I2C address (say for stacking) // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); // Select which 'port' M1, M2, M3 or M4. In this case, M1 Adafruit_DCMotor *myMotor = AFMS.getMotor(1); // You can also make another motor on port M2 //Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2); //#include //AF_DCMotor motor(4); //motor currently attached to M4 on motor shield // initialize the library with the numbers of the interface pins LiquidCrystal lcd(22, 31, 35, 34, 43, 42); int vel = 0; //velocity needs initializing int time = 0; //time needs initializing int dum = 0; //dummy differentiates time or velocity input int x = 0; //first velocity digit int y = 0; //second velocity digit int z = 0; //third velocity digit int e = 0; //first time digit int f = 0; //second time digit int g = 0; //third time digit int T = 0; // Counting down time int remArray[] = {100,101,102,103,104,105,106,107,108,109,110,111,0,112,113,114,1,2,3,115,4,5,6,116,7,8,9}; //this array holds digits to replace input from the miniremote int velArray[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //this array holds velocity variables. Probably more than it should ever need. int timeArray[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //this array holds time variables. Probably more than it should ever need. int c = 0; //used to read initial input int d = 0; //used to read velocity inputs int k = 0; //used to properly place velocity inputs int q = 0; //used to properly place time inputs int lastcode = -1; //initialized as -1 to prevent start-up errors w/ IR sensor int backLight = 48; // pin 48 will control the backlight int w = 0; //if w = 1, the velocity input was BAD (over 255) int R = 0; // used to turn off the spin coater after the specified time int L = 0; // used to turn off the spin coater after the specified time void setup() { Serial.begin(9600); // set up Serial library at 9600 bps pinMode(backLight, OUTPUT); digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off. Serial.println("Motor test!"); // turn on motor AFMS.begin(); myMotor->setSpeed(200); myMotor->run(RELEASE); lcd.begin(16, 2); // Print a message to the LCD. } void loop() { if (vel == 0) { lcd.setCursor(0,0); lcd.print("Input Vel:"); lcd.setCursor(0,1); lcd.print("Input Time:"); } if ((R == 1) && (L == 0)) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Speed="); lcd.setCursor(6,0); lcd.print(vel); lcd.setCursor(0,1); lcd.print("Time="); lcd.setCursor(5,1); lcd.print(time); lcd.setCursor(0,0); L = 1; } // want to print millis()/1000-T to update time remaining, but doesn't work int c = remote.listen(1); // remote.listen(#) => # of seconds to wait before timing out! (This repeats until a command is entered) if (c >= 0) { Serial.println("Received code #"); Serial.println(c, DEC); lastcode = c; } else if (c == -3) { Serial.print("Repeat ("); Serial.print(lastcode); Serial.println(")"); } else if (c == -2) { Serial.println("Data error"); } else { Serial.println("Timed out waiting!"); //c = 0; Serial.print("c ="); Serial.println(c); } d = remArray[c]; lcd.setCursor(11,1); if ( k>= 1){ lcd.print(timeArray[0]); Serial.print(timeArray[0]); Serial.print("*");} // write different variable q instead of k for time and this may work lcd.setCursor(12,1); if ( k>= 2){ lcd.print(timeArray[1]); Serial.print(timeArray[1]); Serial.print("**");} lcd.setCursor(13,1); if ( k>= 3){ lcd.print(timeArray[2]); Serial.print(timeArray[2]); Serial.print("***");} lcd.setCursor(10,0); if ( q>= 1){ lcd.print(velArray[0]); Serial.print(velArray[0]); Serial.print("/");} lcd.setCursor(11,0); if ( q>= 2){ lcd.print(velArray[1]); Serial.print(velArray[1]); Serial.print("//");} lcd.setCursor(12,0); if ( q>= 3){ lcd.print(velArray[2]); Serial.print(velArray[2]); Serial.print("///"); lcd.setCursor(10,0); if (w == 1) { lcd.print("BAD"); } } w = 0; switch(d) { case 105: q = 0; // q was k dum = 1; Serial.println("Velocity Confirmed"); lcd.clear(); break; case 112: k = 0; dum = 2; Serial.println("Time Confirmed"); lcd.clear(); break; case 0: if (dum == 1) { velArray[q] = d; // q was k q++; } if (dum == 2) { timeArray[k] = d; k++; } Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 1: if (dum == 1) { velArray[q] = d; q++;} if (dum == 2) { timeArray[k] = d; k++;} Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 2: if (dum == 1) { velArray[q] = d; q++;} if (dum == 2) { timeArray[k] = d; k++; } Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 3: if (dum == 1) { velArray[q] = d; q++;} if (dum == 2) { timeArray[k] = d; k++; } Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 4: if (dum == 1) { velArray[q] = d; q++;} if (dum == 2) { timeArray[k] = d; k++; } Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 5: if (dum == 1) { velArray[q] = d; q++;} if (dum == 2) { timeArray[k] = d; k++; } Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 6: if (dum == 1) { velArray[q] = d; q++;} if (dum == 2) { timeArray[k] = d; k++; } Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 7: if (dum == 1) { velArray[q] = d; q++;} if (dum == 2) { timeArray[k] = d; k++; } Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 8: if (dum == 1) { velArray[q] = d; q++;} if (dum == 2) { timeArray[k] = d; k++; } Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 9: if (dum == 1) { velArray[q] = d; q++;} if (dum == 2) { timeArray[k] = d; k++; } Serial.print("k ="); Serial.println(k); Serial.print("q="); Serial.println(q); break; case 109: x = (velArray[0] * 100); y = (velArray[1] * 10 ); z = (velArray[2]); vel = x + y + z; R = 1; if (vel >= 255) { vel = 0; w = 1; R = 0; } Serial.print("Velocity ="); Serial.println(vel); //Vel is above, Time is below e = (timeArray[0] * 100); f = (timeArray[1] * 10 ); g = (timeArray[2]); time = e + f + g; T = millis()/1000; Serial.print("Time ="); Serial.println(time); Serial.print("T="); Serial.println(T); break; /* //This is for a 'killswitch' on the remote. By pressing "stop", stop all motion. However I could not get it to work case 106: vel = 0; time = 0; motor.run(FORWARD); motor.setSpeed(vel); Serial.print("Ok, ok, jeez..."); break; */ } // uint8_t i; if (time >= ((millis()/1000) -T)) { myMotor->run(FORWARD); myMotor->setSpeed(vel); Serial.print("millis()/1000="); Serial.println(millis()/1000); } else { vel = 0; myMotor->setSpeed(vel); R = 0; L = 0; } }