diff options
author | Anthony Wang | 2022-10-13 16:30:03 -0400 |
---|---|---|
committer | Anthony Wang | 2022-10-13 16:30:03 -0400 |
commit | e69bd166c35f04c63937033c5b8d301b81803eb1 (patch) | |
tree | 4cc523aea3e14357f7c9dead67b9230f0d26dd8f /week6/week6.ino | |
parent | f69bfee67cde8b0416cc39975b9fe11924bd958a (diff) |
Finish brushless motor
Diffstat (limited to 'week6/week6.ino')
-rw-r--r-- | week6/week6.ino | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/week6/week6.ino b/week6/week6.ino new file mode 100644 index 0000000..34b5fd0 --- /dev/null +++ b/week6/week6.ino @@ -0,0 +1,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); +} |