Imagine | Develop | Create
#include <LiquidCrystal.h> #include <AccelStepper.h> LiquidCrystal lcd(2, 4, 5, 6, 7, 8); #define upPIN 0 #define startstopPIN 1 #define downPIN 10 #define limitPIN 3 //#define InPinA 16 //#define InPinB 19 //#define InSePinA 9 //#define InSePinB 14 //#define InSePinC 15 #define OutPinA 19 #define OutPinB 16 #define OutSePinA 9 #define OutSePinB 14 #define OutSePinC 15 #define en 10 #define i 3 #define steps 23//1000 long Dipping = 30; long unsigned down = 1; long unsigned up = 1; long pause = 1; bool run = 1; unsigned int data[8]; AccelStepper stepper[8]; unsigned long currenttime[8]; void setup() { lcd.begin(16, 2); //pinMode(en, OUTPUT); //digitalWrite(en, HIGH); pinMode(OutSePinA, OUTPUT); pinMode(OutSePinB, OUTPUT); pinMode(OutSePinC, OUTPUT); // pinMode(InSePinA, OUTPUT); //pinMode(InSePinB, OUTPUT); //pinMode(InSePinC, OUTPUT); //pinMode(InPinA, INPUT); //pinMode(InPinB, INPUT); pinMode(OutPinA, OUTPUT); pinMode(OutPinB, OUTPUT); pinMode(upPIN, INPUT); pinMode(startstopPIN, INPUT); pinMode(downPIN, INPUT); pinMode(limitPIN, INPUT); selectLED(i); stepper[i] = AccelStepper(1,OutPinB,OutPinA); stepper[i].setMaxSpeed(200*steps/60); stepper[i].setAcceleration(100.0); restdip(); } void loop() { run = 1; digitalWrite(en, HIGH); lcd.clear(); lcd.print("Dipping Distances"); while( digitalRead(startstopPIN) == LOW) { lcd.setCursor(0,1); lcd.print(Dipping); lcd.print(" mm "); delay(100); if(digitalRead(upPIN) == HIGH)Dipping++; if(digitalRead(downPIN) == HIGH)Dipping--; if(Dipping > 100) Dipping = 100; if(Dipping < 1) Dipping = 1; } delay(100); while(digitalRead(startstopPIN) == HIGH); delay(100); lcd.clear(); lcd.print("Down Speed"); while(digitalRead(startstopPIN) == LOW) { lcd.setCursor(0,1); lcd.print(pause); lcd.print(" mS "); delay(100); if(digitalRead(upPIN) == HIGH)pause = pause+100; if(digitalRead(downPIN) == HIGH)pause = pause-100; if(pause > 60000) pause = 60000; if(pause < 1) pause = 1; } delay(100); while(digitalRead(startstopPIN) == HIGH); delay(100); lcd.clear(); lcd.print("Up Speed"); while(digitalRead(startstopPIN) == LOW) { lcd.setCursor(0,1); lcd.print(up); lcd.print(" mS "); delay(100); if(digitalRead(upPIN) == HIGH)up++; if(digitalRead(downPIN) == HIGH)up--; if(up > 100) up = 100; if(up < 1) up = 1; } delay(100); while(digitalRead(startstopPIN) == HIGH); delay(100); lcd.clear(); lcd.print("Start Dipping"); while(digitalRead(startstopPIN) == LOW) { lcd.setCursor(0,1); if(run) {lcd.print("Yes");} else {lcd.print("No ");} delay(100); if(digitalRead(upPIN) == HIGH)run = 1; if(digitalRead(downPIN) == HIGH)run = 0; } delay(100); while(digitalRead(startstopPIN) == HIGH); delay(100); if(!run){return;} restdip(); digitalWrite(en, LOW); lcd.clear(); lcd.print("Runnning"); stepper[i].setSpeed(down); stepper[i].move(Dipping*steps); while(stepper[i].distanceToGo()) { stepper[i].run(); } delay(pause); stepper[i].setSpeed(up); while(digitalRead(limitPIN) == LOW) { stepper[i].move(-1*Dipping*steps); stepper[i].run(); } digitalWrite(en, HIGH); delay(100); while(digitalRead(startstopPIN) == HIGH); delay(100); lcd.clear(); lcd.print("Finished"); while(digitalRead(startstopPIN) == LOW) {} delay(100); while(digitalRead(startstopPIN) == HIGH); delay(100); } void selectLED(byte A) { switch (A) { case 0: digitalWrite(OutSePinA, LOW); digitalWrite(OutSePinB, LOW); digitalWrite(OutSePinC, LOW); break; case 1: digitalWrite(OutSePinA, HIGH); digitalWrite(OutSePinB, LOW); digitalWrite(OutSePinC, LOW); break; case 2: digitalWrite(OutSePinA, LOW); digitalWrite(OutSePinB, HIGH); digitalWrite(OutSePinC, LOW); break; case 3: digitalWrite(OutSePinA, HIGH); digitalWrite(OutSePinB, HIGH); digitalWrite(OutSePinC, LOW); break; case 4: digitalWrite(OutSePinA, LOW); digitalWrite(OutSePinB, LOW); digitalWrite(OutSePinC, HIGH); break; case 5: digitalWrite(OutSePinA, HIGH); digitalWrite(OutSePinB, LOW); digitalWrite(OutSePinC, HIGH); break; case 6: digitalWrite(OutSePinA, LOW); digitalWrite(OutSePinB, HIGH); digitalWrite(OutSePinC, HIGH); break; case 7: digitalWrite(OutSePinA, HIGH); digitalWrite(OutSePinB, HIGH); digitalWrite(OutSePinC, HIGH); break; case 8: digitalWrite(OutSePinA, LOW); digitalWrite(OutSePinB, LOW); digitalWrite(OutSePinC, LOW); break; break; } } void restdip() { digitalWrite(en, LOW); lcd.clear(); lcd.print("Resetting"); while(digitalRead(limitPIN) == LOW) { stepper[i].move(-100); stepper[i].run(); } stepper[i].move(0); stepper[i].stop(); digitalWrite(en, HIGH); }