You are on page 1of 2

#include <Servo.

h>

int motorPin1 = 4; // Blue - 28BYJ48 pin 1


int motorPin2 = 5; // Pink - 28BYJ48 pin 2
int motorPin3 = 6; // Yellow - 28BYJ48 pin 3
int motorPin4 = 7; // Orange - 28BYJ48 pin 4

int button1pin = 10;


int button2pin = 12; // choose the input pin (for a pushbutton)

int button1push = 0;
int button2push = 0; // variable for reading the pin status

void setup() {
pinMode(button1pin,INPUT_PULLUP);
pinMode(button2pin,INPUT_PULLUP);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Serial.begin(9600);
}

void loop() {
// int ct;
int p1=8; // Pins IN1 and IN3 in stepper driver for coil A
int p2=8;
int p3=8; // Pins IN2 and IN4 are for the coil B
int p4=8;
int d=3; // Delay in milliseconds between successive steps
//int a; // Read voltage from potentiometer
button1push = digitalRead(button1pin);
button2push = digitalRead(button2pin);
Serial.println(button1push);
Serial.println(button2push);

// for (ct=0;ct<=2000;ct++){
//a=analogRead(0);
if (button1push == LOW){
//if (a>612){
p1=4;
p2=6;
p3=5;
p4=7;
}
//if (a<412){
else if (button2push == LOW){
p1=4;
p2=6;
p3=7;
p4=5;
}
//if (a>412 & a<512){
else {
p1=8; // Any unused pin
p2=8;
p3=8;
p4=8;
}

digitalWrite(p1,HIGH); // A1
digitalWrite(p2,LOW); //A2
digitalWrite(p3,LOW); // B1
digitalWrite(p4,LOW); // B2
delay(d);

digitalWrite(p1,LOW); // A1
digitalWrite(p2,LOW); // A2
digitalWrite(p3,HIGH); // B1
digitalWrite(p4,LOW); // B2
delay(d);

digitalWrite(p1,LOW); // A1
digitalWrite(p2,HIGH); // A2
digitalWrite(p3,LOW); // B1
digitalWrite(p4,LOW); // B2
delay(d);

digitalWrite(p1,LOW); // A1
digitalWrite(p2,LOW); // A2
digitalWrite(p3,LOW); // B1
digitalWrite(p4,HIGH); // B2
delay(d);

You might also like