Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Stepper.h>
- const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
- // for your motor
- const int buttonPin = 9; // the number of the pushbutton pin
- const int ledPin = 13; // the number of the LED pin
- // variables will change:
- int buttonState = 0; // variable for reading the pushbutton status
- boolean flag;
- // initialize the stepper library on pins 8 through 11:
- Stepper myStepper(stepsPerRevolution, 3, 4, 5, 6);
- int stepCount = 0; // number of steps the motor has taken
- void obrotSilnika() {
- Serial.println("obrot");
- for (int i = 0; i < 206; i++) {
- // map it to a range from 0 to 100:
- int motorSpeed = map(255, 0, 1023, 0, 100);
- // set the motor speed:
- if (motorSpeed > 0) {
- myStepper.setSpeed(motorSpeed);
- // step 1/100 of a revolution:
- myStepper.step(stepsPerRevolution / 100);
- }
- }
- Serial.println("Obrot koniec");
- delay(500);
- flag = true;
- }
- void setup() {
- // put your setup code here, to run once:
- pinMode(LED_BUILTIN, OUTPUT);
- pinMode(ledPin, OUTPUT);
- // initialize the pushbutton pin as an input:
- pinMode(buttonPin, INPUT);
- Serial.begin(9600);
- flag = true;
- }
- void polej(int l) {
- Serial.println("zaczynam lac");
- digitalWrite(ledPin, HIGH);
- delay(l);
- digitalWrite(ledPin, LOW);
- Serial.println("nalane");
- delay(500);
- obrotSilnika();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- buttonState = digitalRead(buttonPin);
- if (buttonState == HIGH and flag) {
- for (int i = 0; i < 5; i++) {
- flag = false;
- Serial.println("polewam!");
- polej(1000);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement