Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include the library code:
- #include <LiquidCrystal.h>
- #include <Wire.h>
- #include <Stepper.h>
- int potPin = 1; // select the input pin for the potentiometer for stepper motor speed
- int val = 0; // variable to store the value coming from the sensor
- int steps = 0; //variable to store number of steps taken
- int extruded = 0; //to record how much material has been extruded
- int stepSpeed = 0; //spped of stepper motor
- int Distance = 0; //
- // Define stepper motor connections and steps per revolution:
- #define dirPin 2
- #define stepPin 3
- #define stepsPerRevolution 3200
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(22, 23,26, 28, 30, 32);
- void setup() {
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- pinMode(stepPin, OUTPUT);
- pinMode(dirPin, OUTPUT);
- }
- void loop() {
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- val = analogRead(potPin); // read the value from the sensor
- lcd.print(val);
- delay(600);
- digitalWrite(dirPin, HIGH);
- // Spin the stepper motor 1 revolution slowly:
- for (int i = 0; i < stepsPerRevolution; i++) {
- // These four lines result in 1 step:
- digitalWrite(stepPin, HIGH);
- delayMicroseconds(20);
- digitalWrite(stepPin, LOW);
- delayMicroseconds(20);
- }
- //
- // // Set the spinning direction counterclockwise:
- // digitalWrite(dirPin, LOW);
- //
- // // Spin the stepper motor 1 revolution quickly:
- // for (int i = 0; i < stepsPerRevolution; i++) {
- // // These four lines result in 1 step:
- // digitalWrite(stepPin, HIGH);
- // delayMicroseconds(10);
- // digitalWrite(stepPin, LOW);
- // delayMicroseconds(1000);
- // }
- // delay(1000);
- // // Set the spinning direction clockwise:
- // digitalWrite(dirPin, HIGH);
- // // Spin the stepper motor 5 revolutions fast:
- // for (int i = 0; i < 5 * stepsPerRevolution; i++) {
- // // These four lines result in 1 step:
- // digitalWrite(stepPin, HIGH);
- // delayMicroseconds(500);
- // digitalWrite(stepPin, LOW);
- // delayMicroseconds(500);
- // }
- // delay(1000);
- // // Set the spinning direction counterclockwise:
- // digitalWrite(dirPin, LOW);
- // // Spin the stepper motor 5 revolutions fast:
- // for (int i = 0; i < 5 * stepsPerRevolution; i++) {
- // // These four lines result in 1 step:
- // digitalWrite(stepPin, HIGH);
- // delayMicroseconds(500);
- // digitalWrite(stepPin, LOW);
- // delayMicroseconds(500);
- // }
- // delay(1000);
- //
- lcd.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement