Project

General

Profile

Revision c5d6b0e8

IDc5d6b0e8075c55da9cf18670acfee64bc219fdd8
Parent 347a6e5d
Child 0c873a67

Added by Matthew Sebek about 10 years ago

Adding better arduino code.

View differences:

arduino/RCbuggyMega/RCbuggyMega.ino
1 1
/*
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
 *  
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
 
13 8
 */
14
#include <Servo.h> 
15
Servo myservo;  // create servo object to control a servo 
16

  
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 9

  
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
10
//#include <SoftwareSerial.h>
11
#include <Servo.h> 
30 12

  
31
#define PIN_HALL_EFFECT_IN 10
13
Servo myservo;  // create servo object to control a servo 
32 14

  
33
// Packet-sending variables
15
//SoftwareSerial xbee(2, 3); // RX, TX
34 16
unsigned long timer = 0L;
35 17
char data;
36 18
String message;
37 19
char intbuf[32];
38

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

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

  
27
int brakePin = 8;
28
int brakeLedPin = 5;
29

  
49 30
void setup()  {
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 
31
  Serial.begin(9600);
32
  //Serial.println( "Arduino started sending bytes via XBee" );
33
  Serial1.begin(9600);
34
  
35
  pinMode(4, OUTPUT);
36
  pinMode(5, OUTPUT);
37
  pinMode(8, OUTPUT);
38
  
39
  brake_init(brakePin, brakeLedPin); // initialize the brake with brake pin and led brake pin
40
  
41
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
58 42
  myservo.write(133);
59 43
}
60 44

  
......
137 121
  // sets the servo position
138 122
  myservo.write(steeringAngle);
139 123
}
140

  
124

  

Also available in: Unified diff