archive/Arduino/MotorTest/MotorTest.ino

76 lines
1.5 KiB
C++

int inA1 = 8; // wire 1 (blue)
int inA2 = 9; // wire 2 (pink)
int inB1 = 10; // wire 3 (yellow)
int inB2 = 11; // wire 4 (orange)
int counter = 0;
//wire 5 (Red) is a VCC and should be put to 5V, with this setup it is not needed, but it is good to know if you make something like an 8 step spinup
int stepDelay = 2;
void setup() {
pinMode(inA1, OUTPUT);
pinMode(inA2, OUTPUT);
pinMode(inB1, OUTPUT);
pinMode(inB2, OUTPUT);
pinMode(A1,INPUT);
}
void loop(){
Serial.println(String(analogRead(A1)));
Serial.println("hi");
/*for(int i =0;i<1600;i++) {
step1();
step2();
step3();
step4();
}
stopMotor();
delay(500);
for(int j=0;j<1600;j++) {
step3();
step2();
step1();
step4();
}
stopMotor();
delay(500);*/
}
void step1() {
digitalWrite(inA1, LOW);
digitalWrite(inA2, HIGH);
digitalWrite(inB1, HIGH);
digitalWrite(inB2, LOW);
delay(stepDelay);
}
void step2() {
digitalWrite(inA1, LOW);
digitalWrite(inA2, HIGH);
digitalWrite(inB1, LOW);
digitalWrite(inB2, HIGH);
delay(stepDelay);
}
void step3() {
digitalWrite(inA1, HIGH);
digitalWrite(inA2, LOW);
digitalWrite(inB1, LOW);
digitalWrite(inB2, HIGH);
delay(stepDelay);
}
void step4() {
digitalWrite(inA1, HIGH);
digitalWrite(inA2, LOW);
digitalWrite(inB1, HIGH);
digitalWrite(inB2, LOW);
delay(stepDelay);
}
void stopMotor() {
digitalWrite(inA1, LOW);
digitalWrite(inA2, LOW);
digitalWrite(inB1, LOW);
digitalWrite(inB2, LOW);
}