summaryrefslogtreecommitdiff
path: root/week6/week6.ino
diff options
context:
space:
mode:
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);
+}