Browse Source

更新 'testPwm.js'

Caner 3 years ago
parent
commit
8b923f7ae1
1 changed files with 13 additions and 7 deletions
  1. 13 7
      testPwm.js

+ 13 - 7
testPwm.js

@@ -17,21 +17,27 @@ class ContrlService {
             }
         })
         console.log('测试开始');
-        // test
-        let a = 128
-        setInterval(() => {
-            this.PWM.setPulseLength(3, this.Servo2pwm(a));                  
+        let a = 90
+        const t = setInterval(() => {
+            if(a >= 160) {
+                clearInterval(t)
+                // this.PWM.setPulseLength(1, this.Servo2pwm(130));
+                return
+            }
+            a++
+            this.PWM.setPulseLength(1, this.Servo2pwm(a));
             console.log(a);
-        }, 50);
+        }, 20);
     }
 
     /**
-     * 舵机换算比例:摇杆范围0-256,PWM范围1000~1500~2000
+     * 舵机换算比例:摇杆范围0-256,PWM范围500~1500~2500
      * @param {number} v 
      * @returns 
      */
     Servo2pwm(v) {
-        return parseInt(v / (256 / 1000)) + 1000
+        return parseInt(v / (256 / 2000)) + 500
+        // return parseInt(v / (256 / 1000)) + 1000
     }
 }
 new ContrlService()