Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Stepper library
- #include <Stepper.h>
- //LCD libraray
- #include <LiquidCrystal.h>
- #define led 13
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- // koraka po punom krugu
- const int stepsPerRevolution = 200;
- // Step motor se spaja na pinove
- Stepper myStepper(stepsPerRevolution, 7,8,9,10);
- // varijabla za trenutne korake
- int stepCount = 0;
- void setup() {
- pinMode(A1, INPUT);
- // Postavke LCD-a
- lcd.begin(16, 2);
- // Print a message to the LCD.
- lcd.print("Test koračnog motora!");
- }
- void loop() {
- // pročitaj vrijednost potenciometra
- int sensorReading = analogRead(A0);
- // pretvori vrijednost potenciometra u brzinu
- int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
- // postavi brzinu motora
- if (motorSpeed > 0) {
- myStepper.setSpeed(motorSpeed);
- //Postavi smjer ovisno o prekidaču
- if(digitalRead(A1))
- {
- // step 1/100 of a revolution:
- myStepper.step(stepsPerRevolution/100);
- }
- else
- {
- // step 1/100 of a revolution:
- myStepper.step(-(stepsPerRevolution/100));
- }
- }
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- lcd.setCursor(0, 1);
- // ispiši brzinu motora
- lcd.print(motorSpeed);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement