SHARE
TWEET

Stepper Code v0.3

Orion5001 Oct 21st, 2019 (edited) 227 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. #define pot_in A3
  10. #define rocker 9
  11. #define PUL 7
  12. #define DIR 6
  13. #define ENA 5
  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.   pinMode (PUL, OUTPUT);
  27.   pinMode (DIR, OUTPUT);
  28.   pinMode (ENA, OUTPUT);
  29.  
  30.   pinMode (pot_in, INPUT);
  31.   pinMode (rocker, INPUT);
  32.  
  33.   int minimum_speed_delay = 50;
  34.   int maximum_speed_delay = 1;
  35.   int acceleration_delay = 2;
  36.   int count = 0;
  37.   int current_speed_delay = 100;
  38.  
  39.   delay(5000);
  40. }
  41.  
  42. void loop() {
  43.   if (digitalRead(rocker) == HIGH) {
  44.     if (count == 0) {                //Initial acceleration to minimum speed
  45.       lcd.clear();
  46.       lcd.setCursor(0, 1);
  47.       lcd.print("Motor is");
  48.       lcd.setCursor(0, 2);
  49.       lcd.print("accelerating");
  50.       int current_speed_delay = 0;
  51.       while (current_speed_delay > minimum_speed_delay) {
  52.         digitalWrite(DIR, LOW);
  53.         digitalWrite(ENA, HIGH);
  54.         digitalWrite(PUL, HIGH);
  55.         delayMicroseconds(current_speed_delay);
  56.         digitalWrite(PUL, LOW);
  57.         delayMicroseconds(current_speed_delay);
  58.         int current_speed_delay = current_speed_delay - acceleration_delay;
  59.         int count = count + 1;
  60.       }
  61.     }
  62.     else if (count > 0) {             //Motor speed = multiple of potiometer reading
  63.       lcd.clear();
  64.       lcd.setCursor(0, 0);
  65.       lcd.print("Motor is operating");
  66.       lcd.setCursor(0, 2);
  67.       lcd.print("at");
  68.       lcd.setCursor(8, 2);
  69.       lcd.print("RPMs");
  70.       while (digitalRead(rocker) == HIGH) {
  71.         digitalWrite(DIR, LOW);
  72.         digitalWrite(ENA, HIGH);
  73.         digitalWrite(PUL, HIGH);
  74.         delayMicroseconds(current_speed_delay);
  75.         digitalWrite(PUL, LOW);
  76.         delayMicroseconds(current_speed_delay);
  77.         int potent = analogRead(pot_in);
  78.         current_speed_delay = constrain(potent, maximum_speed_delay, minimum_speed_delay);
  79.         int count = count + 1;
  80.  
  81.         lcd.setCursor(3, 2);
  82.         lcd.print(int(current_speed_delay));
  83.       }
  84.     }
  85.   }
  86.   else if (digitalRead(rocker) == LOW) {        //Turning motor off
  87.     if (count > 0) {                            //Deceleration to 0
  88.       lcd.clear();
  89.       lcd.setCursor(0, 1);
  90.       lcd.print("Motor is");
  91.       lcd.setCursor(0, 2);
  92.       lcd.print("decelerating");
  93.       while (current_speed_delay < 100) {
  94.         digitalWrite(DIR, LOW);
  95.         digitalWrite(ENA, HIGH);
  96.         digitalWrite(PUL, HIGH);
  97.         delayMicroseconds(current_speed_delay);
  98.         digitalWrite(PUL, LOW);
  99.         delayMicroseconds(current_speed_delay);
  100.         int current_speed_delay = current_speed_delay + acceleration_delay;
  101.         int count = count + 1;
  102.         int count = 0;
  103.       }
  104.     }
  105.     else if (count == 0) {                                       //Motor speed = 0
  106.       lcd.clear();
  107.       lcd.setCursor(3, 1);
  108.       lcd.print("Motor is off");
  109.       while (digitalRead(rocker) == LOW) {
  110.         delay(10);
  111.       }
  112.     }
  113.   }
  114.  
  115. }
  116.  
  117.  
  118.  
  119. ------------------
  120.  
  121.  
  122. Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"
  123.  
  124. C:\Users\zhowe\Google Drive (zhowell@mymail.mines.edu)\10-19 Current Semester [Fall 2019]\[MEGN 301] Mechanical Integration & Design\Extruder Project\Stepper Motor Code\Stepper_Code_without_accel\Stepper_Code_without_accel.ino: In function 'void loop()':
  125.  
  126. Stepper_Code_without_accel:44:9: error: 'count' was not declared in this scope
  127.  
  128.      if (count == 0) {                //Initial acceleration to minimum speed
  129.  
  130.          ^~~~~
  131.  
  132. C:\Users\zhowe\Google Drive (zhowell@mymail.mines.edu)\10-19 Current Semester [Fall 2019]\[MEGN 301] Mechanical Integration & Design\Extruder Project\Stepper Motor Code\Stepper_Code_without_accel\Stepper_Code_without_accel.ino:44:9: note: suggested alternative: 'round'
  133.  
  134.      if (count == 0) {                //Initial acceleration to minimum speed
  135.  
  136.          ^~~~~
  137.  
  138.          round
  139.  
  140. Stepper_Code_without_accel:51:36: error: 'minimum_speed_delay' was not declared in this scope
  141.  
  142.        while (current_speed_delay > minimum_speed_delay) {
  143.  
  144.                                     ^~~~~~~~~~~~~~~~~~~
  145.  
  146. C:\Users\zhowe\Google Drive (zhowell@mymail.mines.edu)\10-19 Current Semester [Fall 2019]\[MEGN 301] Mechanical Integration & Design\Extruder Project\Stepper Motor Code\Stepper_Code_without_accel\Stepper_Code_without_accel.ino:51:36: note: suggested alternative: 'current_speed_delay'
  147.  
  148.        while (current_speed_delay > minimum_speed_delay) {
  149.  
  150.                                     ^~~~~~~~~~~~~~~~~~~
  151.  
  152.                                     current_speed_delay
  153.  
  154. Stepper_Code_without_accel:58:57: error: 'acceleration_delay' was not declared in this scope
  155.  
  156.          int current_speed_delay = current_speed_delay - acceleration_delay;
  157.  
  158.                                                          ^~~~~~~~~~~~~~~~~~
  159.  
  160. Stepper_Code_without_accel:74:27: error: 'current_speed_delay' was not declared in this scope
  161.  
  162.          delayMicroseconds(current_speed_delay);
  163.  
  164.                            ^~~~~~~~~~~~~~~~~~~
  165.  
  166. In file included from sketch\Stepper_Code_without_accel.ino.cpp:1:0:
  167.  
  168. Stepper_Code_without_accel:78:49: error: 'maximum_speed_delay' was not declared in this scope
  169.  
  170.          current_speed_delay = constrain(potent, maximum_speed_delay, minimum_speed_delay);
  171.  
  172.                                                  ^
  173.  
  174. C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:95:41: note: in definition of macro 'constrain'
  175.  
  176.  #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
  177.  
  178.                                          ^~~
  179.  
  180. Stepper_Code_without_accel:78:70: error: 'minimum_speed_delay' was not declared in this scope
  181.  
  182.          current_speed_delay = constrain(potent, maximum_speed_delay, minimum_speed_delay);
  183.  
  184.                                                                       ^
  185.  
  186. C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:95:60: note: in definition of macro 'constrain'
  187.  
  188.  #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
  189.  
  190.                                                             ^~~~
  191.  
  192. Stepper_Code_without_accel:87:9: error: 'count' was not declared in this scope
  193.  
  194.      if (count > 0) {                            //Deceleration to 0
  195.  
  196.          ^~~~~
  197.  
  198. C:\Users\zhowe\Google Drive (zhowell@mymail.mines.edu)\10-19 Current Semester [Fall 2019]\[MEGN 301] Mechanical Integration & Design\Extruder Project\Stepper Motor Code\Stepper_Code_without_accel\Stepper_Code_without_accel.ino:87:9: note: suggested alternative: 'round'
  199.  
  200.      if (count > 0) {                            //Deceleration to 0
  201.  
  202.          ^~~~~
  203.  
  204.          round
  205.  
  206. Stepper_Code_without_accel:93:14: error: 'current_speed_delay' was not declared in this scope
  207.  
  208.        while (current_speed_delay < 100) {
  209.  
  210.               ^~~~~~~~~~~~~~~~~~~
  211.  
  212. Stepper_Code_without_accel:100:57: error: 'acceleration_delay' was not declared in this scope
  213.  
  214.          int current_speed_delay = current_speed_delay + acceleration_delay;
  215.  
  216.                                                          ^~~~~~~~~~~~~~~~~~
  217.  
  218. Stepper_Code_without_accel:102:13: error: redeclaration of 'int count'
  219.  
  220.          int count = 0;
  221.  
  222.              ^~~~~
  223.  
  224. C:\Users\zhowe\Google Drive (zhowell@mymail.mines.edu)\10-19 Current Semester [Fall 2019]\[MEGN 301] Mechanical Integration & Design\Extruder Project\Stepper Motor Code\Stepper_Code_without_accel\Stepper_Code_without_accel.ino:101:13: note: 'int count' previously declared here
  225.  
  226.          int count = count + 1;
  227.  
  228.              ^~~~~
  229.  
  230. Multiple libraries were found for "Wire.h"
  231.  Used: C:\Program
  232. Multiple libraries were found for "LiquidCrystal_I2C.h"
  233.  Used: C:\Users\zhowe\Documents\Arduino\libraries\NewLiquidCrystal_lib
  234. exit status 1
  235. 'count' was not declared in this scope
  236.  
  237. This report would have more information with
  238. "Show verbose output during compilation"
  239. option enabled in File -> Preferences.
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