Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

7. Gripperbot > Programming the Gripperbot

Programming the Gripperbot

Here’s the sketch for the Gripperbot base:

#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Bricktronics.h>

// Make: Lego and Arduino Projects
// Chapter 7: Gripperbot: Base
// Website: http://www.wayneandlayne.com/bricktronics

Bricktronics brick = Bricktronics();
Motor r = Motor(&brick, 1);
Motor l = Motor(&brick, 2);

void setup() { 
  Serial.begin(9600);
  brick.begin();
  r.begin();
  l.begin();
}

void process_incoming_command(char cmd, char arg0) 
{
  int speed = 0;
  switch (cmd)
  {
  case '6':
  case 6: 
    speed = arg0*2;
    l.set_speed(speed);
    break;
  case '7':
  case 7: 
    speed = arg0*2;
    r.set_speed(speed);
    break;
  default:
    break;
  }
}

void loop() {
  while (Serial.available() < 3)
  {
    //Do nothing while we wait for a full command to come in.
  }
  char start = Serial.read();
  if (start != '*') 
  {
    return; 
  }

  char cmd = Serial.read(); 
  char arg0 = Serial.read();
  process_incoming_command(cmd, arg0);
}

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint