Created
May 29, 2020 07:27
-
-
Save matisiekpl/a52c50bead3b5eb5572d46783d841bce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Servo.h> | |
| Servo myservo; // create servo object to control a servo | |
| // twelve servo objects can be created on most boards | |
| int pos = 0; // variable to store the servo position | |
| #include <Stepper.h> //dodajemy do szkicu bibliotekę obsługującą silniki krokowe | |
| # | |
| define ILOSC_KROKOW 32 //definiujemy stałą gdzie podajemy ilość kroków zależną od użytego silnika w naszym przypadku 32 | |
| Stepper mojSilnik(ILOSC_KROKOW, 8, 9, 10, 11); //tutaj podajemy piny w Arduino, którymi sterujemy silnikiem | |
| Stepper silnik2(ILOSC_KROKOW, 2, 3, 4, 5); | |
| void setup() | |
| { | |
| myservo.attach(7); // attaches the servo on pin 9 to the servo object | |
| } | |
| void loop() | |
| { | |
| mojSilnik.setSpeed(200); //podajemy prędkość obrotu wyrażona w rpm | |
| mojSilnik.step(512); //linijka powoduje obrót ośki silnika o 90 stopni | |
| delay(2000); // linijka powoduje odczekanie 2 sekund (wartosc w milisekundach 1000 = 1s) | |
| silnik2.setSpeed(200); | |
| silnik2.step(512); | |
| delay(2000); | |
| for (pos = 0; pos <= 45; pos += 1) { // goes from 0 degrees to 45 degrees | |
| // in steps of 1 degree | |
| myservo.write(pos); // tell servo to go to position in variable 'pos' | |
| delay(15); // waits 15ms for the servo to reach the position | |
| for (pos = 45; pos >= 0; pos -= 1) { // goes from 45 degrees to 0 degrees | |
| myservo.write(pos); // tell servo to go to position in variable 'pos' | |
| delay(15); // waits 15ms for the servo to reach the position | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment