ClassBotLib is an arduino library to control a small 3D printed drawing robot based on MakersBox's Arduino Chassis for Drawing Robot. In my classes I use a custom Arduino Shield to drive a pair of 28BYJ-48 stepper motors using two ULN2003 driver IC's. The shield has room for a SPI Serial Ram Chip and a I2C Serial EEPROM that are not used in this library. Take a look at the TinyBasic Plus ClassBot Edition Github repo for another way to run the bot.
A #define statement is used to select which of the Hershey vector fonts to use for drawing text. If you do not select a font (or mispell the name of the font) FONT_ROWMANS will be used by default. This must be done before including the "ClassBot.h" header file.
#define FONT_SCRIPTS
#include "ClassBot.h"
- FONT_ASTROLOGY
- FONT_CURSIVE
- FONT_CYRILC_1
- FONT_CYRILLIC
- FONT_FUTURAL
- FONT_FUTURAM
- FONT_GOTHGBT
- FONT_GOTHGRT
- FONT_GOTHICENG
- FONT_GOTHICGER
- FONT_GOTHICITA
- FONT_GOTHITT
- FONT_GREEKC
- FONT_GREEK
- FONT_GREEKS
- FONT_JAPANESE
- FONT_MARKERS
- FONT_MATHLOW
- FONT_MATHUPP
- FONT_METEOROLOGY
- FONT_MUSIC
- FONT_ROWMAND
- FONT_ROWMANS
- FONT_ROWMANT
- FONT_SCRIPTC
- FONT_SCRIPTS
- FONT_SYMBOLIC
- FONT_TIMESG
- FONT_TIMESIB
- FONT_TIMESI
- FONT_TIMESRB
- FONT_TIMESR
ClassBot::ClassBot(int l1 = 9, int l2 = 7, int l3 = 8, int l4 = 6, int r1 = 2, int r2 = 4, int r3 = 3, int r4 = 5, int ServoPin = A0);
Constructor, create's the ClassBot object and configures the library. Be sure to set your stepper motor pins if your bot is wired differently then the default.
| Parameter | Description | Default Value |
|---|---|---|
| l1 | left motor pin 1 | D9 |
| l2 | left motor pin 2 | D7 |
| l3 | left motor pin 3 | D8 |
| l4 | left motor pin 4 | D6 |
| r1 | right motor pin 1 | D2 |
| r2 | right motor pin 2 | D4 |
| r3 | right motor pin 3 | D3 |
| r4 | right motor pin 4 | D5 |
| ServoPin | Pen servo pin | A0 |
void penDown();
Lower the pen to the paper.
void penUp();
Raise the pen off the paper
void moveForward(float distance);
Move forward distance milimeters.
void moveBackward(float distance);
Move backward distance milimeters.
void turnLeft(float degrees);
Turn degrees to the left.
void turnRight(float degrees);
Turn degrees to the right.
void turnTo(float heading);
Turn to face heading compass heading in degrees.
void moveTo(long x, long y, boolean penUp=true, float scale = 1);
Move to cartesian coordinates x,y with the pen up or down as specified by penUp. scale sets the coordinate size in milimeters and defaults to 1mm.
void drawChar(char ch, float scale = 1);
Draw the character ch at the scale size.
void writeText(char *str, float scale = 1);
Write the string str at the scale size
void done();
Turn off steppers motors and raise the pen.
void setX(long x);
Set the current cartesian X coordinate to x.
void setY(long y);
Set the current cartesian Y coordinate to y.
void setH(float degrees);
Set the current heading in degrees
boolean getPen();
Returns true id the pen is raised.
long getX();
Return the current cartesian X coordinate of the bot.
long getY();
Return the current cartesian Y coordinate of the bot.
float getH();
Return the current heading of the bot.
//
// Draw a box
//
#include "ClassBot.h"
int side = 20;
void setup()
{
ClassBot bot;
bot.penDown();
for (int i=1; i <5; i++) {
bot.moveForward(side);
bot.turnLeft(90);
}
bot.done();
}
void loop()
{
}
#include "ClassBot.h"
int radiusX = 30;
int radiusY = 30;
int sides = 20; // polygon number of sides
void setup()
{
ClassBot bot;
float step = 2 * PI / sides;
float theta;
int x, y, xx, yy;
int startX = bot.getX();
int startY = bot.getY();
int startH = bot.getH();
for (theta = 0; theta < 2 * PI; theta += step) {
x = radiusX * cos(theta);
y = radiusY * sin(theta);
if (theta == 0) {
xx = x;
yy = y;
bot.moveTo(x, y, true);
} else {
bot.moveTo(x, y, false);
}
}
bot.moveTo(xx, yy, false);
bot.moveTo(startX, startY, true);
bot.turnTo(startH);
bot.done();
}
void loop()
{
}
//
// Draw a star
//
#include "ClassBot.h"
int side = 20;
int points = 5;
void setup()
{
ClassBot bot;
float angle = 180.0 - 180.0 / points;
int i;
bot.penDown();
for (i = 0; i < points; i++) {
bot.moveForward(side);
bot.turnLeft(angle);
bot.moveForward(side);
}
bot.done();
}
void loop()
{
}
//
// Simple text drawing example
//
// You can use a #define statement to select which font to use
// if you do not select a font (or mispell the name of the font)
// FONT_ROWMANS will be used by default. This must be done before
// the #include "ClassBot.h" line.
#define FONT_SCRIPTS
#include "ClassBot.h"
void setup()
{
ClassBot bot;
bot.writeText((char *)"Hello!", 2);
bot.done();
}
void loop()
{
}
