Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. // include the library code:
  2. #include <LiquidCrystal.h>
  3. #include <Wire.h>
  4. #include <Stepper.h>
  5.  
  6. int potPin = 1; // select the input pin for the potentiometer for stepper motor speed
  7. int val = 0; // variable to store the value coming from the sensor
  8. int steps = 0; //variable to store number of steps taken
  9. int extruded = 0; //to record how much material has been extruded
  10. int stepSpeed = 0; //spped of stepper motor
  11. int Distance = 0; //
  12.  
  13. // Define stepper motor connections and steps per revolution:
  14. #define dirPin 2
  15. #define stepPin 3
  16. #define stepsPerRevolution 3200
  17.  
  18.  
  19.  
  20. // initialize the library with the numbers of the interface pins
  21. LiquidCrystal lcd(22, 23,26, 28, 30, 32);
  22.  
  23. void setup() {
  24. // set up the LCD's number of columns and rows:
  25. lcd.begin(16, 2);
  26. pinMode(stepPin, OUTPUT);
  27. pinMode(dirPin, OUTPUT);
  28. }
  29.  
  30. void loop() {
  31. // set the cursor to column 0, line 1
  32. // (note: line 1 is the second row, since counting begins with 0):
  33. val = analogRead(potPin); // read the value from the sensor
  34. lcd.print(val);
  35. delay(600);
  36.  
  37. digitalWrite(dirPin, HIGH);
  38.  
  39. // Spin the stepper motor 1 revolution slowly:
  40. for (int i = 0; i < stepsPerRevolution; i++) {
  41. // These four lines result in 1 step:
  42. digitalWrite(stepPin, HIGH);
  43.  
  44. delayMicroseconds(20);
  45.  
  46. digitalWrite(stepPin, LOW);
  47.  
  48. delayMicroseconds(20);
  49. }
  50.  
  51. //
  52. // // Set the spinning direction counterclockwise:
  53. // digitalWrite(dirPin, LOW);
  54. //
  55. // // Spin the stepper motor 1 revolution quickly:
  56. // for (int i = 0; i < stepsPerRevolution; i++) {
  57. // // These four lines result in 1 step:
  58. // digitalWrite(stepPin, HIGH);
  59. // delayMicroseconds(10);
  60. // digitalWrite(stepPin, LOW);
  61. // delayMicroseconds(1000);
  62. // }
  63. // delay(1000);
  64. // // Set the spinning direction clockwise:
  65. // digitalWrite(dirPin, HIGH);
  66. // // Spin the stepper motor 5 revolutions fast:
  67. // for (int i = 0; i < 5 * stepsPerRevolution; i++) {
  68. // // These four lines result in 1 step:
  69. // digitalWrite(stepPin, HIGH);
  70. // delayMicroseconds(500);
  71. // digitalWrite(stepPin, LOW);
  72. // delayMicroseconds(500);
  73. // }
  74. // delay(1000);
  75. // // Set the spinning direction counterclockwise:
  76. // digitalWrite(dirPin, LOW);
  77. // // Spin the stepper motor 5 revolutions fast:
  78. // for (int i = 0; i < 5 * stepsPerRevolution; i++) {
  79. // // These four lines result in 1 step:
  80. // digitalWrite(stepPin, HIGH);
  81. // delayMicroseconds(500);
  82. // digitalWrite(stepPin, LOW);
  83. // delayMicroseconds(500);
  84. // }
  85. // delay(1000);
  86. //
  87.  
  88. lcd.clear();
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement