SHARE
TWEET

Stepper Code V 0.1

Orion5001 Oct 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //
  3. //
  4.  
  5. #include <Wire.h>
  6. #include <LiquidCrystal_I2C.h>
  7. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
  8.  
  9. #include <AccelStepper.h>
  10. AccelStepper stepper(1, 7, 6);
  11.  
  12. #define pot_in A3
  13. #define rocker 9
  14.  
  15. void setup() {
  16.   lcd.begin(20, 4);
  17.   lcd.setCursor(0, 0);
  18.   lcd.print("Welcome to");
  19.   lcd.setCursor(0, 1);
  20.   lcd.print("Team Plastic");
  21.   lcd.setCursor(0, 2);
  22.   lcd.print("String Theory's");
  23.   lcd.setCursor(0, 3);
  24.   lcd.print("Plastic Extruder!");
  25.  
  26.   stepper.setMaxSpeed(10000);
  27.   stepper.setAcceleration(100);
  28.   stepper.setSpeed(0);
  29.  
  30.   pinMode (pot_in, INPUT);
  31.   pinMode (rocker, INPUT);
  32.  
  33.   delay(5000);
  34. }
  35.  
  36. void loop() {
  37.   if (digitalRead(rocker) == HIGH) {
  38.     if (stepper.speed() == 0) {
  39.       lcd.clear();
  40.       lcd.setCursor(0, 1);
  41.       lcd.print("Motor is");
  42.       lcd.setCursor(0, 2);
  43.       lcd.print("accelerating");
  44.  
  45.       int potent = analogRead(pot_in);
  46.       stepper.moveTo(100000000000000000000000);
  47.       stepper.setSpeed(potent);
  48.       stepper.runSpeed();
  49.  
  50.     }
  51.     else if (stepper.speed() > 0) {
  52.       lcd.clear();
  53.       lcd.setCursor(0, 0);
  54.       lcd.print("Motor is operating");
  55.       lcd.setCursor(0, 2);
  56.       lcd.print("at");
  57.       lcd.setCursor(8, 2);
  58.       lcd.print("RPMs");
  59.       while (digitalRead(rocker) == HIGH) {
  60.         int potent = analogRead(pot_in);
  61.         stepper.moveTo(5);
  62.         stepper.setSpeed(potent*0.5);
  63.         stepper.run();
  64.        
  65.         lcd.setCursor(3, 2);
  66.         lcd.print(int(stepper.speed()));
  67.       }
  68.     }
  69.   }
  70.   else if (digitalRead(rocker) == LOW) {
  71.     if (stepper.speed() > 0) {
  72.       lcd.clear();
  73.       lcd.setCursor(0, 1);
  74.       lcd.print("Motor is");
  75.       lcd.setCursor(0, 2);
  76.       lcd.print("decelerating");
  77.       while (stepper.speed() > 1) {
  78.         stepper.stop();
  79.         delay(10);
  80.       }
  81.     }
  82.     else {
  83.       lcd.clear();
  84.       lcd.setCursor(3, 1);
  85.       lcd.print("Motor is off");
  86.       while (digitalRead(rocker) == LOW) {
  87.         delay(10);
  88.       }
  89.     }
  90.   }
  91.  
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top