From a99e483a35177dab8fc6d91ec4d70a4781dffefa Mon Sep 17 00:00:00 2001 From: Nikodem Bartnik <39432165+NikodemBartnik@users.noreply.github.com> Date: Fri, 1 Jun 2018 20:10:34 +0200 Subject: [PATCH] Create 28BYJ-48.ino --- 28BYJ-48/28BYJ-48.ino | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 28BYJ-48/28BYJ-48.ino diff --git a/28BYJ-48/28BYJ-48.ino b/28BYJ-48/28BYJ-48.ino new file mode 100644 index 0000000..f385abe --- /dev/null +++ b/28BYJ-48/28BYJ-48.ino @@ -0,0 +1,87 @@ +//Written By Nikodem Bartnik - nikodembartnik.pl +#define STEPPER_PIN_1 9 +#define STEPPER_PIN_2 10 +#define STEPPER_PIN_3 11 +#define STEPPER_PIN_4 12 +int step_number = 0; +void setup() { +pinMode(STEPPER_PIN_1, OUTPUT); +pinMode(STEPPER_PIN_2, OUTPUT); +pinMode(STEPPER_PIN_3, OUTPUT); +pinMode(STEPPER_PIN_4, OUTPUT); + +} + +void loop() { + + OneStep(false); + delay(2); + + +} + + +void OneStep(bool dir){ + if(dir){ +switch(step_number){ + case 0: + digitalWrite(STEPPER_PIN_1, HIGH); + digitalWrite(STEPPER_PIN_2, LOW); + digitalWrite(STEPPER_PIN_3, LOW); + digitalWrite(STEPPER_PIN_4, LOW); + break; + case 1: + digitalWrite(STEPPER_PIN_1, LOW); + digitalWrite(STEPPER_PIN_2, HIGH); + digitalWrite(STEPPER_PIN_3, LOW); + digitalWrite(STEPPER_PIN_4, LOW); + break; + case 2: + digitalWrite(STEPPER_PIN_1, LOW); + digitalWrite(STEPPER_PIN_2, LOW); + digitalWrite(STEPPER_PIN_3, HIGH); + digitalWrite(STEPPER_PIN_4, LOW); + break; + case 3: + digitalWrite(STEPPER_PIN_1, LOW); + digitalWrite(STEPPER_PIN_2, LOW); + digitalWrite(STEPPER_PIN_3, LOW); + digitalWrite(STEPPER_PIN_4, HIGH); + break; +} + }else{ + switch(step_number){ + case 0: + digitalWrite(STEPPER_PIN_1, LOW); + digitalWrite(STEPPER_PIN_2, LOW); + digitalWrite(STEPPER_PIN_3, LOW); + digitalWrite(STEPPER_PIN_4, HIGH); + break; + case 1: + digitalWrite(STEPPER_PIN_1, LOW); + digitalWrite(STEPPER_PIN_2, LOW); + digitalWrite(STEPPER_PIN_3, HIGH); + digitalWrite(STEPPER_PIN_4, LOW); + break; + case 2: + digitalWrite(STEPPER_PIN_1, LOW); + digitalWrite(STEPPER_PIN_2, HIGH); + digitalWrite(STEPPER_PIN_3, LOW); + digitalWrite(STEPPER_PIN_4, LOW); + break; + case 3: + digitalWrite(STEPPER_PIN_1, HIGH); + digitalWrite(STEPPER_PIN_2, LOW); + digitalWrite(STEPPER_PIN_3, LOW); + digitalWrite(STEPPER_PIN_4, LOW); + + +} + } +step_number++; + if(step_number > 3){ + step_number = 0; + } +} + +