b5139b365463e77553c83eeb2b22d6ac29d568d3
Tech-dat/acturator-dat/motor-dat/servo-dat/servo-dat.md
| ... | ... | @@ -86,30 +86,6 @@ Taking the 180-degree angle servo as an example, the corresponding control relat |
| 86 | 86 | |
| 87 | 87 | ### arduino |
| 88 | 88 | |
| 89 | - #include <Servo.h> |
|
| 90 | - Servo servo; |
|
| 91 | - int angle = 10; |
|
| 92 | - void setup() { |
|
| 93 | - servo.attach(8); |
|
| 94 | - servo.write(angle); |
|
| 95 | - } |
|
| 96 | - void loop() |
|
| 97 | - { |
|
| 98 | - // scan from 0 to 180 degrees |
|
| 99 | - for(angle = 10; angle < 180; angle++) |
|
| 100 | - { |
|
| 101 | - servo.write(angle); |
|
| 102 | - delay(15); |
|
| 103 | - } |
|
| 104 | - // now scan back from 180 to 0 degrees |
|
| 105 | - for(angle = 180; angle > 10; angle--) |
|
| 106 | - { |
|
| 107 | - servo.write(angle); |
|
| 108 | - delay(15); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | 89 | |
| 114 | 90 | ## servo calibration |
| 115 | 91 | |
| ... | ... | @@ -240,7 +216,9 @@ connector to a [[crank-dat]] |
| 240 | 216 | |
| 241 | 217 | |
| 242 | 218 | |
| 219 | +## code |
|
| 243 | 220 | |
| 221 | +- [[code-dat]] |
|
| 244 | 222 | |
| 245 | 223 | |
| 246 | 224 | ## ref |
code-dat/code-dat.md
| ... | ... | @@ -13,6 +13,9 @@ |
| 13 | 13 | - [[esp8266-HDK-dat]] |
| 14 | 14 | |
| 15 | 15 | |
| 16 | + |
|
| 17 | + |
|
| 18 | + |
|
| 16 | 19 | ## repo |
| 17 | 20 | |
| 18 | 21 | - [[arduino-dat]] |
code-dat/code-motor-servo/code-motor-servo.ino
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | + |
|
| 2 | + |
|
| 3 | +#include <Servo.h> |
|
| 4 | + |
|
| 5 | +Servo servo; |
|
| 6 | +int angle = 10; |
|
| 7 | + |
|
| 8 | +void setup() |
|
| 9 | +{ |
|
| 10 | + servo.attach(8); |
|
| 11 | + servo.write(angle); |
|
| 12 | +} |
|
| 13 | + |
|
| 14 | +void loop() |
|
| 15 | +{ |
|
| 16 | + // scan from 0 to 180 degrees |
|
| 17 | + for (angle = 10; angle < 180; angle++) |
|
| 18 | + { |
|
| 19 | + servo.write(angle); |
|
| 20 | + delay(15); |
|
| 21 | + } |
|
| 22 | + // now scan back from 180 to 0 degrees |
|
| 23 | + for (angle = 180; angle > 10; angle--) |
|
| 24 | + { |
|
| 25 | + servo.write(angle); |
|
| 26 | + delay(15); |
|
| 27 | + } |
|
| 28 | +} |
code-dat/motor-driver-code-dat/dual-foot-dat/dual-foot-2.ino
| ... | ... | @@ -74,7 +74,7 @@ h2 { text-align:center; color:#333; } |
| 74 | 74 | <div class="servo-panel"> |
| 75 | 75 | <div style="align-self:center;font-weight:bold">Servo14:</div> |
| 76 | 76 | <button class="sml-btn s90-btn" onclick="sendCmd('s90')">90°</button> |
| 77 | - <button class="sml-btn s180-btn" onclick="sendCmd('s180')">180°</button> |
|
| 77 | + <button class="sml-btn s180-btn" onclick="sendCmd('s-90')">-90°</button> |
|
| 78 | 78 | </div> |
| 79 | 79 | <div class="relay-panel"> |
| 80 | 80 | <div class="relay-item"><div style="font-weight:bold">Relay1:</div><button class="relay-btn on-btn" onclick="sendCmd('r1_on')">ON</button><button class="relay-btn off-btn" onclick="sendCmd('r1_off')">OFF</button></div> |
| ... | ... | @@ -99,7 +99,7 @@ void handleRoot() { |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | void handleControl() { |
| 102 | - // Simple command-based control: cmd=fw|rv|st|s90|s180|rX_on|rX_off |
|
| 102 | + // Simple command-based control: cmd=fw|rv|st|s90|s-90|rX_on|rX_off |
|
| 103 | 103 | if (server.hasArg("cmd")) { |
| 104 | 104 | String c = server.arg("cmd"); |
| 105 | 105 | if (c == "fw") { |
| ... | ... | @@ -121,10 +121,10 @@ void handleControl() { |
| 121 | 121 | // Servo4 to 90 degrees |
| 122 | 122 | servo4.write(90); |
| 123 | 123 | Serial.println("Servo14: 90°"); |
| 124 | - } else if (c == "s180") { |
|
| 125 | - // Servo4 to 180 degrees |
|
| 126 | - servo4.write(180); |
|
| 127 | - Serial.println("Servo14: 180°"); |
|
| 124 | + } else if (c == "s-90") { |
|
| 125 | + // Servo4 to -90 degrees |
|
| 126 | + servo4.write(-90); |
|
| 127 | + Serial.println("Servo14: -90°"); |
|
| 128 | 128 | } else if (c == "r1_on") { |
| 129 | 129 | digitalWrite(RELAY1_PIN, HIGH); |
| 130 | 130 | Serial.println("Relay1: ON"); |