對滑板進行組裝和測試前的最後一步是編寫控制軟體並上傳至Arduino。在將Arduino連接到您的筆記型電腦之前,請確保沒有透過BEC由滑板電池供電。在由BEC供電的情況下將Arduino連接到電腦的USB埠可能會損壞電腦的USB埠或者Arduino,也有可能兩個同時受到損壞!
您可以點擊此處獲取我在github上編寫的Arduino控制軟體!現在,該軟體還只是一個非常簡單的代碼草圖,能夠實現將雙手柄的輸入轉換為馬達轉速,並傳送給ESC。我希望在不久之後能夠寫出更高級的控制軟體,以提升滑板的性能。您可以根據自己的喜好調整和改進代碼,並與我分享您的見解!
滑板控制Arduino草圖:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | /*         * Rahul Iyer       */       #include <Servo.h>       #include <Wire.h>       #include <ArduinoNunchuk.h>       #define BAUDRATE 19200       #define CHUCK_ZERO 133       #define CHUCK_MAX 255       #define ESC_ZERO 90       #define SPEED_MAX 130       ArduinoNunchuk nunchuk = ArduinoNunchuk();       int escOutputValue = ESC_ZERO;       float currentOutputValue = ESC_ZERO;       int resetCounter = 0;       Servo ESC;       void setup()       {       ESC.attach(9);       Serial.begin(BAUDRATE);       nunchuk.init();       delay(100);       }       void loop()       {       resetCounter++;       if (resetCounter==40)       {          resetCounter=0;          nunchuk.init();          delay(100);       }       nunchuk.update();       // Serial.print(nunchuk.analogX, DEC);       // Serial.print(' ');       // Serial.print(nunchuk.analogY, DEC);       // Serial.print(' ');       // Serial.print(nunchuk.accelX, DEC);       // Serial.print(' ');       // Serial.print(nunchuk.accelY, DEC);       // Serial.print(' ');       // Serial.print(nunchuk.accelZ, DEC);       // Serial.print(' ');       // Serial.print(nunchuk.zButton, DEC);       // Serial.print(' ');       // Serial.print(nunchuk.cButton, DEC);       // Serial.print(' ');       int yValue = nunchuk.analogY;       if (yValue<CHUCK_ZERO)       {          yValue = CHUCK_ZERO; // no backwards       }       // escOutputValue = map(yValue, CHUCK_ZERO, CHUCK_MAX, ESC_ZERO, SPEED_MAX); //linear relationship between joystick value and ESC output value--deemed not good enough :P       if (yValue == CHUCK_ZERO)       {          escOutputValue = ESC_ZERO; //if joystick is at zero, no power to motor (coast)          currentOutputValue = ESC_ZERO; //reset       }       else       {          int maxPossibleSpeed = map (yValue, CHUCK_ZERO, CHUCK_MAX, ESC_ZERO, SPEED_MAX);          if (escOutputValue > maxPossibleSpeed)          {            escOutputValue = maxPossibleSpeed;          }          else          {            float increment = (1.0 * (yValue - CHUCK_ZERO)) / (CHUCK_MAX - CHUCK_ZERO);            currentOutputValue += increment;            escOutputValue = (int) currentOutputValue;            if (escOutputValue > maxPossibleSpeed)            {              escOutputValue = maxPossibleSpeed;            }          }       }       ESC.write(escOutputValue);       Serial.println(escOutputValue); //for debugging       } | 
