1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// brushess motor: synchronous mode
#define AIN1 0 // coil A, input pin 1
#define AIN2 1 // coil A, input pin 2
#define BIN1 2 // coil B, input pin 1
#define BIN2 3 // coil B, input pin 2
void setup() {
// set coil control pins as Teensy outputs
for (int i = 0; i < 8; ++i) pinMode(i, OUTPUT);
}
void set_coil(int in1, int v1, int in2, int v2) {
digitalWrite(in1, v1);
digitalWrite(in2, v2);
digitalWrite(in1+4, v1);
digitalWrite(in2+4, v2);
delay(15);
}
void loop(){
set_coil(AIN1,LOW,AIN2,HIGH);
set_coil(BIN1,HIGH,BIN2,LOW);
set_coil(AIN1,HIGH,AIN2,LOW);
set_coil(BIN1,LOW,BIN2,HIGH);
}
|