Stap 3: programma
Voor het uploaden van het programma dat u wilt installeren van de plugin Linkit één samen met de arduino IDE. Hier vindt u instructies over hoe dat te doen in de officiële website. U kunt ook de IDE met de Linkit één plugin voorgeïnstalleerd van GitHub downloaden.
#define bluetooth Serial#include Servo myServo;char cmd[100]; int cmdIndex;void exeCmd() { // "servo" is the servo motor id if(cmd[0]=='s' && cmd[1]=='e' && cmd[2]=='r' && cmd[3]=='v' && cmd[4]=='o' && cmd[5]==' ') { int val = 0; for(int i=6; cmd[i]!=0; i++) { val = val*10 + (cmd[i]-'0'); } // if cmd is "servo 1234", val will be 1234 myServo.writeMicroseconds(val); } }void setup() { delay(500); // wait for bluetooth module to start bluetooth.begin(115200); // Bluetooth default baud is 115200 myServo.attach(4, 1000, 2000); cmdIndex = 0; }void loop() { if(bluetooth.available()) { char c = (char)bluetooth.read(); if(c=='\n') { cmd[cmdIndex] = 0; exeCmd(); // execute the command cmdIndex = 0; // reset the cmdIndex } else { cmd[cmdIndex] = c; if(cmdIndex<99) cmdIndex++; } } }