From 2b8576914fc9bba9ceae15a7e5254cf7cd6152f7 Mon Sep 17 00:00:00 2001 From: altaf-pi Date: Mon, 8 Apr 2024 13:44:22 +0700 Subject: add files --- Arduino/stepper/stepper.ino | 115 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 Arduino/stepper/stepper.ino (limited to 'Arduino/stepper/stepper.ino') diff --git a/Arduino/stepper/stepper.ino b/Arduino/stepper/stepper.ino new file mode 100644 index 0000000..26786f4 --- /dev/null +++ b/Arduino/stepper/stepper.ino @@ -0,0 +1,115 @@ +// sesuaikan dengan PIN yang dipasang +int INA1=14; +int INA2=15; +int INA3=16; +int INA4=17; + +int INB1=18; +int INB2=19; +int INB3=20; +int INB4=21; +//int step = 100; +int delaytime=2; //makin kecil delay, makin cepat motor berputar + +int pinStatus = 13; + +void setup(){ + pinMode(INA1,OUTPUT); + pinMode(INA2,OUTPUT); + pinMode(INA3,OUTPUT); + pinMode(INA4,OUTPUT); + + pinMode(INB1,OUTPUT); + pinMode(INB2,OUTPUT); + pinMode(INB3,OUTPUT); + pinMode(INB4,OUTPUT); + + pinMode(pinStatus, INPUT); + + Serial.begin(9600); +} + +void loop(){ + //maju 60; + //for (int i=0; i<1000; i++){ + if (!digitalRead(pinStatus)) { + maju(); + } + //} + Serial.println(digitalRead(pinStatus)); +} + +void maju(){ +//step 4 +step1(); +delay(delaytime); +//step 3 +step2(); +delay(delaytime); +//step 2 +step3(); +delay(delaytime); +//step 1 +step4(); +delay(delaytime); +} + +void mundur(){ +//step 4 +step4(); +delay(delaytime); +//step 3 +step3(); +delay(delaytime); +//step 2 +step2(); +delay(delaytime); +//step 1 +step1(); +delay(delaytime); +} + +void step1(){ +digitalWrite(INA1,LOW); +digitalWrite(INB1,LOW); +digitalWrite(INA2,LOW); +digitalWrite(INB2,HIGH); +digitalWrite(INA3,HIGH); +digitalWrite(INB3,HIGH); +digitalWrite(INA4,HIGH); +digitalWrite(INB4,LOW); +} +void step2(){ +digitalWrite(INA1,HIGH); +digitalWrite(INB1,HIGH); +digitalWrite(INA2,LOW); +digitalWrite(INB2,HIGH); +digitalWrite(INA3,LOW); +digitalWrite(INB3,LOW); +digitalWrite(INA4,HIGH); +digitalWrite(INB4,LOW); +} +void step3(){ +digitalWrite(INA1,HIGH); +digitalWrite(INB1,HIGH); +digitalWrite(INA2,HIGH); +digitalWrite(INB2,LOW); +digitalWrite(INA3,LOW); +digitalWrite(INB3,LOW); +digitalWrite(INA4,LOW); +digitalWrite(INB4,HIGH); + + +} +void step4(){ +digitalWrite(INA1,LOW); +digitalWrite(INB1,LOW); +digitalWrite(INA2,HIGH); +digitalWrite(INB2,LOW); +digitalWrite(INA3,HIGH); +digitalWrite(INB3,HIGH); +digitalWrite(INA4,LOW); + +digitalWrite(INB4,HIGH); + +} -- cgit v1.2.3