summaryrefslogtreecommitdiff
path: root/week6/week6.ino
diff options
context:
space:
mode:
authorAnthony Wang2022-10-13 16:30:03 -0400
committerAnthony Wang2022-10-13 16:30:03 -0400
commite69bd166c35f04c63937033c5b8d301b81803eb1 (patch)
tree4cc523aea3e14357f7c9dead67b9230f0d26dd8f /week6/week6.ino
parentf69bfee67cde8b0416cc39975b9fe11924bd958a (diff)
Finish brushless motor
Diffstat (limited to 'week6/week6.ino')
-rw-r--r--week6/week6.ino24
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);
+}