From e69bd166c35f04c63937033c5b8d301b81803eb1 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 13 Oct 2022 16:30:03 -0400 Subject: Finish brushless motor --- week6/week6.ino | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 week6/week6.ino 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); +} -- cgit v1.2.3-70-g09d2