source: robotics/car/firmware/car/car.ino @ 42180f7

Last change on this file since 42180f7 was 42180f7, checked in by Steve Castellotti <sc@…>, 8 years ago
  • drive commands added
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2
3Puzzlebox - Robotics - Car
4
5Puzzlebox Robotics car driving sketch.
6
7Copyright Puzzlebox Productions, LLC (2014)
8
9This code is released under the GNU Pulic License (GPL) version 2
10
11This software is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15You should have received a copy of the GNU General Public
16License along with this code; if not, write to the Free Software
17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19For more information about this licence please refer to http://www.gnu.org/copyleft/gpl.html
20
21For more details about the product please check http://puzzlebox.info
22
23Original Author: Steve Castellotti <sc@puzzlebox.info>
24
25Modified 2014-06-16
26by Steve Castellotti <sc@puzzlebox.info>
27
28*/
29
30#include <Servo.h>
31
32#define SERVO_PIN_BRAKE 7
33#define SERVO_PIN_DIRECTION 8
34#define SERVO_PIN_TURN 9
35
36#define DEBUG_OUTPUT 1 // 1 for debug
37
38Servo servoBrake;
39Servo servoDirection;
40Servo servoTurn;
41
42char _command;
43
44
45// ################################################################
46
47/////////
48//SETUP//
49/////////
50
51void setup() {
52       
53  Serial.begin(115200);
54
55  servoBrake.attach(SERVO_PIN_BRAKE);
56  servoDirection.attach(SERVO_PIN_DIRECTION);
57  servoTurn.attach(SERVO_PIN_TURN);
58
59} // setup
60
61
62// ################################################################
63
64/////////////
65//MAIN LOOP//
66/////////////
67
68void loop() {
69
70  parseSerialInput();
71
72} // Main loop
73
74
75// ################################################################
76
77int parseValue() {
78 
79  char inByte=0;
80  int a=0;
81  int b=0;
82  int c=0;
83  int newValue=0;
84
85  while (Serial.available() == 0);
86  inByte = Serial.read() - '0';
87  a = inByte;
88
89  while (Serial.available() == 0);
90  inByte = Serial.read() - '0';
91  b = inByte;
92
93  while (Serial.available() == 0);
94  inByte = Serial.read() - '0';
95  c = inByte;
96
97  newValue = (a * 100) + (b * 10) + c;
98
99  return(newValue);
100
101} // parseValue
102
103
104// ################################################################
105
106void parseSerialInput() {
107
108  if (Serial.available() > 0)  {
109
110    _command = Serial.read();
111
112    #if DEBUG_OUTPUT
113      Serial.print("Serial.read(): ");
114      Serial.println(_command);
115    #endif
116
117    switch (_command) {
118
119      case '0':  driveRepeat(); break;
120      case '1':  driveForward(); break;
121      case '2':  driveStop(); break;
122      case '3':  driveLeft(); break;
123      case '4':  driveRight(); break;
124
125//      case 'S':  setServo(); break;
126//      case 'L':  loopServo(); break;
127
128    }
129   
130  }
131
132} // parseSerialInput()
133
134
135// ################################################################
136
137void driveRepeat() {
138 
139}
140
141// ################################################################
142
143void driveForward() {
144
145}
146
147// ################################################################
148
149void driveStop() {
150
151}
152
153// ################################################################
154
155void driveLeft() {
156
157}
158
159// ################################################################
160
161void driveRight() {
162
163}
164
165// ################################################################
Note: See TracBrowser for help on using the repository browser.