Skip to content

Instantly share code, notes, and snippets.

@clowwindy
Created July 25, 2015 16:13
Show Gist options
  • Save clowwindy/e8117e5efb81cdcf1451 to your computer and use it in GitHub Desktop.
Save clowwindy/e8117e5efb81cdcf1451 to your computer and use it in GitHub Desktop.
BLE Microbot
#include <Servo.h>
#include "GoBLE.h"
#include "Metro.h"
Metro servoMove(50);
Servo myservoLF;
Servo myservoLR;
Servo myservoRF;
Servo myservoRR;
int center = 82;
int minSpeed = 5;
int fullSpeed = 30;
int attached = 0;
int pinLED = 13;
GoBLE Goble(Serial);// init the bluetooth Serial port
int joystickX, joystickY;
int buttonState[7];
int speedL, speedR;
void attach() {
attached = 1;
myservoLF.attach(5);
myservoLR.attach(2);
myservoRF.attach(4);
myservoRR.attach(3);
digitalWrite(pinLED, HIGH);
}
void detach() {
attached = 0;
myservoLF.write(center);
myservoLR.write(center);
myservoRF.write(center);
myservoRR.write(center);
myservoLF.detach();
myservoLR.detach();
myservoRF.detach();
myservoRR.detach();
digitalWrite(pinLED, LOW);
}
void setup(){
Goble.begin();// init Goble and default baudrate is 9600 bps!!!
Serial.begin(9600); // 115200 when powered by battery
pinMode(pinLED, OUTPUT);
}
void loop (){
if(Goble.available()){
joystickX = Goble.readJoystickY() - 128;
joystickY = Goble.readJoystickX() - 128;
buttonState[SWITCH_UP] = Goble.readSwitchUp();
buttonState[SWITCH_LEFT] = Goble.readSwitchLeft();
buttonState[SWITCH_RIGHT] = Goble.readSwitchRight();
buttonState[SWITCH_DOWN] = Goble.readSwitchDown();
buttonState[SWITCH_SELECT] = Goble.readSwitchSelect();
buttonState[SWITCH_START] = Goble.readSwitchStart();
speedL = (joystickY + joystickX) / (255 / fullSpeed);
speedR = (joystickY - joystickX) / (255 / fullSpeed);
}
if (abs(speedL) < minSpeed) {
speedL = 0;
}
if (abs(speedR) < minSpeed) {
speedR = 0;
}
if (servoMove.check()) {
if (speedL == 0 && speedR == 0) {
if (attached) {
detach();
}
} else {
if (!attached) {
attach();
}
myservoLF.write(center - speedL);
myservoLR.write(center - speedL);
myservoRF.write(center + speedR);
myservoRR.write(center + speedR);
}
}
}
Copy link

ghost commented Jan 28, 2018

It shows me an error message...

'GoBLE' does not name a type

And this is the line underlined by red...

GoBLE Goble(Serial);// init the bluetooth Serial port

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment