Skip to content

Instantly share code, notes, and snippets.

@AlexanderBrevig
Created May 26, 2016 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexanderBrevig/7f63cc3312190798c81f5eddb0c8c9f4 to your computer and use it in GitHub Desktop.
Save AlexanderBrevig/7f63cc3312190798c81f5eddb0c8c9f4 to your computer and use it in GitHub Desktop.
For dancing to a song at a live concert
#include <Servo.h>
#include <Braccio2.h>
Servo base;
Servo shoulder;
Servo elbow;
Servo wrist;
Servo rotate;
Servo gripper;
Braccio2 robot(base, shoulder, elbow, wrist, rotate, gripper);
const uint8_t btn = 10;
const uint8_t PRESSED_VAL = LOW;
void setup()
{
randomSeed(analogRead(0));
base.attach(11);
shoulder.attach(10);
elbow.attach(9);
wrist.attach(6);
rotate.attach(5);
gripper.attach(3);
robot.home(3000);
pinMode(btn, INPUT_PULLUP);
moveRandomlyUntilPress()
}
void moveRandomlyUntilPress(){
while (digitalRead(btn) != PRESSED_VAL){
goRandomAndLeft(-1); // fully random
robot.move(3000);
}
}
void goRandomAndLeft(int left){
robot.base(left==0 ? 0 : (left==1 ? 180 : random(0,181))); //go left right or random
robot.shoulder(random(10,171));
robot.elbow(random(0,181));
robot.wrist(random(0,181));
robot.rotate(random(0,181));
robot.gripper(left<0 ? random(20,96) : 20); //random or clap while dancing
}
void waitTillPressed(){while (digitalRead(btn) != PRESSED_VAL);}
void loop()
{
for (int i=0; i<2; i++){
waitTillPressed();
goRandomAndLeft(i%2==0);
robot.move(100);
waitTillPressed();
robot.home(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment