RedBot
RedBot Arduino Library for the Sparkfun RedBot
 All Classes Functions Variables
RedBot.h
1 #ifndef RedBot_h
2 #define RedBot_h
3 
4 #include <Arduino.h>
5 
6 #define L_CTRL_1 2
7 #define L_CTRL_2 4
8 #define PWM_L 5
9 
10 #define R_CTRL_1 7
11 #define R_CTRL_2 8
12 #define PWM_R 6
13 
20 {
21  public:
27  RedBotMotor();
28 
62  void drive(int speed);
63 
96  void leftDrive(int speed);
97 
130  void rightDrive(int speed);
131 
166  void pivot(int speed);
167 
201  void stop();
202 
211  void leftStop();
212 
221  void rightStop();
222 
258  void brake();
259 
269  void leftBrake();
270 
281  void rightBrake();
282 
283  private:
284  void leftFwd(byte speed);
285  void leftRev(byte speed);
286  void rightFwd(byte speed);
287  void rightRev(byte speed);
288 };
289 
297 {
298  public:
310  RedBotSensor(int pin);
311 
318  int read();
319 
327  boolean check();
328 
338  int setBGLevel();
339 
349  int setDetectLevel();
350 
351  private:
352  int _pin;
353  int _BGLevel;
354  int _BGSD;
355  int _detectLevel;
356  int _detectSD;
357 };
358 
359 #define XL_ADDR 0x1D // I2C address of the MMA8452Q accelerometer
360 #define I2C_READ 0x01 // I2C read bit set
361 // Some values we'll load into TWCR a lot
362 #define START_COND 0xA4 // (1<<TWINT) | (1<<TWSTA) | (1<<TWEN)
363 #define STOP_COND 0x94 // (1<<TWINT) | (1<<TWSTO) | (1<<TWEN)
364 #define CLEAR_TWINT 0x84 // (1<<TWINT) | (1<<TWEN)
365 #define NEXT_BYTE 0xC4 // (1<<TWINT) | (1<<TWEA) | (1<<TWEN)
366 
375 {
376  public:
380  RedBotAccel();
381 
389  void read();
390 
398  void enableBump();
399 
409  boolean checkBump();
410 
419  void setBumpThresh(int xThresh);
420 
427  int x;
428 
435  int y;
436 
443  int z;
444 
445  private:
446  void xlWriteBytes(byte addr, byte *buffer, byte len);
447  void xlReadBytes(byte addr, byte *buffer, byte len);
448 };
449 
450 #endif RedBot_h
Definition: RedBot.h:374
void drive(int speed)
Definition: RedBotMotor.cpp:24
void leftStop()
Definition: RedBotMotor.cpp:90
int z
Definition: RedBot.h:443
void stop()
Definition: RedBotMotor.cpp:12
RedBotSensor(int pin)
Definition: RedBotSensor.cpp:4
Definition: RedBot.h:19
boolean checkBump()
Definition: RedBotAccel.cpp:146
void rightStop()
Definition: RedBotMotor.cpp:97
void brake()
Definition: RedBotMotor.cpp:18
Definition: RedBot.h:296
void leftDrive(int speed)
Definition: RedBotMotor.cpp:64
int y
Definition: RedBot.h:435
void rightBrake()
Definition: RedBotMotor.cpp:83
void setBumpThresh(int xThresh)
Definition: RedBotAccel.cpp:157
int x
Definition: RedBot.h:427
int setDetectLevel()
Definition: RedBotSensor.cpp:129
RedBotMotor()
Definition: RedBotMotor.cpp:4
RedBotAccel()
Definition: RedBotAccel.cpp:4
void rightDrive(int speed)
Definition: RedBotMotor.cpp:52
int setBGLevel()
Definition: RedBotSensor.cpp:82
int read()
Definition: RedBotSensor.cpp:9
void leftBrake()
Definition: RedBotMotor.cpp:76
void read()
Definition: RedBotAccel.cpp:58
void enableBump()
Definition: RedBotAccel.cpp:75
void pivot(int speed)
Definition: RedBotMotor.cpp:38
boolean check()
Definition: RedBotSensor.cpp:23