Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <Stepper.h>
  2.  
  3. const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
  4. // for your motor
  5. const int buttonPin = 9; // the number of the pushbutton pin
  6. const int ledPin = 13; // the number of the LED pin
  7.  
  8. // variables will change:
  9. int buttonState = 0; // variable for reading the pushbutton status
  10. boolean flag;
  11.  
  12. // initialize the stepper library on pins 8 through 11:
  13. Stepper myStepper(stepsPerRevolution, 3, 4, 5, 6);
  14.  
  15. int stepCount = 0; // number of steps the motor has taken
  16.  
  17. void obrotSilnika() {
  18. Serial.println("obrot");
  19. for (int i = 0; i < 206; i++) {
  20. // map it to a range from 0 to 100:
  21. int motorSpeed = map(255, 0, 1023, 0, 100);
  22. // set the motor speed:
  23. if (motorSpeed > 0) {
  24. myStepper.setSpeed(motorSpeed);
  25. // step 1/100 of a revolution:
  26. myStepper.step(stepsPerRevolution / 100);
  27. }
  28. }
  29. Serial.println("Obrot koniec");
  30. delay(500);
  31. flag = true;
  32. }
  33.  
  34. void setup() {
  35. // put your setup code here, to run once:
  36. pinMode(LED_BUILTIN, OUTPUT);
  37.  
  38. pinMode(ledPin, OUTPUT);
  39. // initialize the pushbutton pin as an input:
  40. pinMode(buttonPin, INPUT);
  41.  
  42. Serial.begin(9600);
  43. flag = true;
  44. }
  45.  
  46. void polej(int l) {
  47. Serial.println("zaczynam lac");
  48. digitalWrite(ledPin, HIGH);
  49. delay(l);
  50. digitalWrite(ledPin, LOW);
  51. Serial.println("nalane");
  52. delay(500);
  53. obrotSilnika();
  54. }
  55.  
  56. void loop() {
  57. // put your main code here, to run repeatedly:
  58. buttonState = digitalRead(buttonPin);
  59. if (buttonState == HIGH and flag) {
  60. for (int i = 0; i < 5; i++) {
  61. flag = false;
  62. Serial.println("polewam!");
  63. polej(1000);
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement