summaryrefslogtreecommitdiff
path: root/Arduino/stepper/stepper.ino
blob: 26786f421271404442ee72554c6a8c64cda43345 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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);

}