changeset 13:5ec3593bb005

Allow use of any pins for the servos
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 13 Sep 2014 17:08:40 +0200
parents da7ac7636281
children 2d8033ee54af
files katka/katka.ino
diffstat 1 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/katka/katka.ino	Sat Sep 13 16:47:20 2014 +0200
+++ b/katka/katka.ino	Sat Sep 13 17:08:40 2014 +0200
@@ -20,24 +20,24 @@
 // TV remote support
 IRrecv irrecv(2);
 
-const char JOINTS[MAX_SERVO][2] {
-//  reverse, trim
+const char JOINTS[MAX_SERVO][3] {
+//  pin, reverse, trim
 
     // hind right
-    {-1, 5}, // ankle
-    {1, 0},  // knee
+    {6, -1, 5}, // ankle
+    {7, 1, 0},  // knee
 
     // front right
-    {-1, 5}, // ankle
-    {1, -5}, // knee
+    {8, -1, 5}, // ankle
+    {9, 1, -5}, // knee
 
     // front left
-    {-1, 0}, // knee
-    {1, 0}, // ankle
+    {10, -1, 0}, // knee
+    {11, 1, 0}, // ankle
 
     // hind left
-    {-1, 0}, // knee
-    {1, -5}, // ankle
+    {14, -1, 0}, // knee
+    {13, 1, -5}, // ankle
 };
 const char LEGS[4][4] {
 // knee servo, ankle servo, x direction, y direction
@@ -91,13 +91,13 @@
 
 void _move_joint(char joint, double rads) {
     // Move a joint to a position in radians between -PI and PI.
-    rads = ((rads * JOINTS[joint][0]) + PI2);
+    rads = ((rads * JOINTS[joint][1]) + PI2);
     while (rads > _2PI) {
         rads -= _2PI;
     }
     int freq = (SERVO_FREQ_MAX -
                 SERVO_FREQ_MIN) * rads / PI + SERVO_FREQ_MIN;
-    char trim = JOINTS[joint][1];
+    char trim = JOINTS[joint][2];
     freq = min(SERVO_FREQ_MAX, max(SERVO_FREQ_MIN, freq + trim * 10));
     servos[joint].writeMicroseconds(freq);
 }
@@ -134,8 +134,7 @@
 
 void servo_setup() {
     for (char servo = 0; servo < MAX_SERVO; ++servo) {
-        servos[servo].attach(servo + SERVO_PIN_MIN,
-                             SERVO_FREQ_MIN, SERVO_FREQ_MAX);
+        servos[servo].attach(JOINTS[servo][0], SERVO_FREQ_MIN, SERVO_FREQ_MAX);
     }
 }
 
@@ -154,22 +153,29 @@
         switch (ir_results.value) {
             case 0xFF02FD:
                 creep_speed = min(1.0, creep_speed + 0.25);
+                digitalWrite(12, HIGH);
                 break;
             case 0xFF096F:
                 creep_speed = max(-1.0, creep_speed - 0.25);
+                digitalWrite(12, HIGH);
                 break;
             case 0xFFE01E:
                 creep_rotation = min(1.0, creep_rotation + 0.25);
+                digitalWrite(12, HIGH);
                 break;
             case 0xFF906E:
                 creep_rotation = max(-1.0, creep_rotation - 0.25);
+                digitalWrite(12, HIGH);
                 break;
             case 0xFFA857:
                 creep_speed = 0.0;
                 creep_rotation = 0.0;
+                digitalWrite(12, HIGH);
                 break;
         }
         irrecv.resume();
+    } else {
+        digitalWrite(12, LOW);
     }
 }
 
@@ -234,6 +240,8 @@
     servo_setup();
     creep_setup();
     ir_setup();
+    pinMode(12, OUTPUT);
+    digitalWrite(12, LOW);
 }
 
 void loop() {