Project

General

Profile

Revision 02df64f0

ID02df64f076cfabdc1177e1613cd3bb28decf4945
Parent 750e8795
Child 347a6e5d

Added by Matthew Sebek about 10 years ago

Made RCBuggyMega.ino more modular...slightly.

It needs more work. like a good bit more work. And then verification that
the more work actually worked.

View differences:

arduino/RCbuggyMega/RCbuggyMega.ino
1 1
/*
2
  Makes Arduino receive input from xbee and parse data.
3
 
4
 The circuit:
5
 * RX is digital pin 2 (connect to TX of XBee)
6
 * TX is digital pin 3 (connect to RX of XBee)
7
 
2
 * @file RCbuggyMega
3
 * @brief Receives data from XBee, and uses this data to control the buggy. 
4
 *
5
 * Pinout circuit:
6
 *   Serial1: Used for XBee
7
 *     RX is digital pin 2 (connect to TX of XBee)
8
 *     TX is digital pin 3 (connect to RX of XBee)
9
 *
10
 *   Serial: Used for Programming/Debugging
11
 *     Connect for debugging. 
12
 *  
8 13
 */
9

  
10
//#include <SoftwareSerial.h>
11 14
#include <Servo.h> 
12

  
13 15
Servo myservo;  // create servo object to control a servo 
14 16

  
15
//SoftwareSerial xbee(2, 3); // RX, TX
17
#define XBEE_BAUD 9600
18
#define DEBUG_BAUD 9600
19
#define PIN_LED_XBEE_INDICATOR 4
20
#define PIN_LED_BRAKE_DEPLOYED 5
21
// comes on after two seconds of lost connection
22
#define PIN_LED_LOSS_CONNECTION 12 
23

  
24
#define PIN_BRAKE_DEPLOY_OUT 8
25

  
26
#define PIN_SERVO_OUT 9
27

  
28
// Default value for the wheel. 
29
#define SERVO_WHEEL_DEFAULT 133
30

  
31
#define PIN_HALL_EFFECT_IN 10
32

  
33
// Packet-sending variables
16 34
unsigned long timer = 0L;
17 35
char data;
18 36
String message;
19 37
char intbuf[32];
38

  
39
// Buggy variables
20 40
int brake = 0;
21 41
int steeringAngle = 135;
22 42
int pingPong = 1;
43

  
44
// String parsing variables
23 45
int startfound = 0;
24 46
int midfound = 0;
25 47
int endfound = 1;
26 48

  
27 49
void setup()  {
28
  Serial.begin(9600);
29
  //Serial.println( "Arduino started sending bytes via XBee" );
30
  Serial1.begin(9600);
31

  
32
  pinMode(4, OUTPUT);
33
  pinMode(5, OUTPUT);
34
  pinMode(8, OUTPUT);
35
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
50
  // Initialize debug serial and xbee serial. 
51
  Serial.begin(DEBUG_BAUD);
52
  Serial1.begin(XBEE_BAUD);
53

  
54
  pinMode(PIN_LED_XBEE_INDICATOR, OUTPUT);
55
  pinMode(PIN_LED_BRAKE_DEPLOYED, OUTPUT);
56
  pinMode(PIN_BRAKE_DEPLOY_OUT, OUTPUT);
57
  myservo.attach(PIN_SERVO_OUT);  // attaches the servo on pin 9 to the servo object 
36 58
  myservo.write(133);
37 59
}
38 60

  

Also available in: Unified diff