Advertisement
Guest User

step_lcd

a guest
May 14th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. //Stepper library
  2. #include <Stepper.h>
  3. //LCD libraray
  4. #include <LiquidCrystal.h>
  5.  
  6. #define led 13
  7. // initialize the library with the numbers of the interface pins
  8. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  9. // koraka po punom krugu
  10. const int stepsPerRevolution = 200;
  11. // Step motor se spaja na pinove
  12. Stepper myStepper(stepsPerRevolution, 7,8,9,10);
  13. // varijabla za trenutne korake
  14. int stepCount = 0;
  15.  
  16. void setup() {
  17. pinMode(A1, INPUT);
  18. // Postavke LCD-a
  19. lcd.begin(16, 2);
  20. // Print a message to the LCD.
  21. lcd.print("Test koračnog motora!");
  22. }
  23.  
  24. void loop() {
  25. // pročitaj vrijednost potenciometra
  26. int sensorReading = analogRead(A0);
  27. // pretvori vrijednost potenciometra u brzinu
  28. int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  29. // postavi brzinu motora
  30. if (motorSpeed > 0) {
  31. myStepper.setSpeed(motorSpeed);
  32. //Postavi smjer ovisno o prekidaču
  33. if(digitalRead(A1))
  34. {
  35. // step 1/100 of a revolution:
  36. myStepper.step(stepsPerRevolution/100);
  37. }
  38. else
  39. {
  40. // step 1/100 of a revolution:
  41. myStepper.step(-(stepsPerRevolution/100));
  42. }
  43. }
  44. // set the cursor to column 0, line 1
  45. // (note: line 1 is the second row, since counting begins with 0):
  46. lcd.setCursor(0, 1);
  47. // ispiši brzinu motora
  48. lcd.print(motorSpeed);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement