Project

General

Profile

Statistics
| Branch: | Revision:

robobuggy / arduino / RCbuggyMega / RCbuggyMega.ino @ 453e1532

History | View | Annotate | Download (1.55 KB)

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
 
8
 * changes made:
9
 * @author: Auds (ayeoh)
10

    
11
 */
12

    
13
//#include <SoftwareSerial.h>
14
#include <Servo.h>
15

    
16
#define BRAKE_PIN 8
17
#define BRAKE_INDICATOR_PIN 5
18
#define XBEE_LED_PIN 4
19

    
20
#define SERVO_PIN 9
21

    
22
Servo myservo;  // create servo object to control a servo
23

    
24
void setup()  {
25
  Serial.begin(9600);
26
  Serial1.begin(9600);
27

    
28
  xbee_init(XBEE_LED_PIN);
29

    
30
  // initialize the brake with brake pin and led brake pin
31
  brake_init(brakePin, brakeLedPin);
32

    
33

    
34
  myservo.attach(SERVO_PIN);  // attaches the servo on pin 9 to the servo object
35
  myservo.write(STEEING_CENTER);
36
}
37

    
38
void loop()  {
39

    
40
  // receive and parse message from xbee
41
  if(Serial1.available() > 0) {
42

    
43
    timer = millis();
44

    
45
    // read message from xbee
46
    data = Serial1.read();
47

    
48
    parse(data);
49

    
50
    // flop external LED everytime message is recieved
51
    debugMessage();
52

    
53
  } // end receive message
54

    
55
  // brake if it has been greater than 3 seconds since we last got a message
56
  if( (millis() - timer) > 5000L ) {
57
    brake_drop();
58
    exit(1);
59
  }
60

    
61
  /* Stuff I was told not to care about
62
  if((millis() - timer) > 2000L) {
63
    digitalWrite(12, HIGH);
64
  }
65
  else {
66
    digitalWrite(12, LOW);
67
  }*/
68
  
69
  int brake = getBrake();
70
  // make brake LED light up if brakes should be down
71
  if( brake == 0 ) {
72
    brake_drop();
73
  }else {
74
    brake_raise();
75
  }
76

    
77
  int steeringAngle = getSteeringAngle();
78
 
79
 s // sets the servo position
80
  myservo.write(steeringAngle);
81
}
82