A program designed to run on the microbit. Used for driving a buggy.

Dependencies:   microbit

Committer:
AdrianClarke
Date:
Mon Mar 27 12:14:03 2017 +0000
Revision:
0:4aa6e1498925
Initial Code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AdrianClarke 0:4aa6e1498925 1 /*********************************************************
AdrianClarke 0:4aa6e1498925 2 *buggy_functions.h *
AdrianClarke 0:4aa6e1498925 3 *Author: Elijah Orr & Dan Argust *
AdrianClarke 0:4aa6e1498925 4 * *
AdrianClarke 0:4aa6e1498925 5 *A library of functions that can be used to control the *
AdrianClarke 0:4aa6e1498925 6 *RenBuggy. *
AdrianClarke 0:4aa6e1498925 7 *********************************************************/
AdrianClarke 0:4aa6e1498925 8
AdrianClarke 0:4aa6e1498925 9 /* include guards are used to prevent problems caused by
AdrianClarke 0:4aa6e1498925 10 multiple definitions */
AdrianClarke 0:4aa6e1498925 11 #ifndef BUGGY_FUNCTIONS_H
AdrianClarke 0:4aa6e1498925 12 #define BUGGY_FUNCTIONS_H
AdrianClarke 0:4aa6e1498925 13
AdrianClarke 0:4aa6e1498925 14 /* mbed.h must be included in this file also */
AdrianClarke 0:4aa6e1498925 15
AdrianClarke 0:4aa6e1498925 16
AdrianClarke 0:4aa6e1498925 17 /* #define LeftMotorPin P0_3 tells the preprocessor to replace
AdrianClarke 0:4aa6e1498925 18 any mention of LeftMotorPin with P0_3 etc.
AdrianClarke 0:4aa6e1498925 19 This currently used the Large pads labled 0 and 1.
AdrianClarke 0:4aa6e1498925 20 P0_18 is equivelent to pad 8.
AdrianClarke 0:4aa6e1498925 21 P0_16 is equivelent to pad 16.
AdrianClarke 0:4aa6e1498925 22 potential pads could be P0,P1,P8,P12,P2,P16
AdrianClarke 0:4aa6e1498925 23 */
AdrianClarke 0:4aa6e1498925 24 #define LeftMotorPin P0_18
AdrianClarke 0:4aa6e1498925 25 #define RightMotorPin P0_16
AdrianClarke 0:4aa6e1498925 26 #define follow_Speed 0.3
AdrianClarke 0:4aa6e1498925 27
AdrianClarke 0:4aa6e1498925 28
AdrianClarke 0:4aa6e1498925 29 /*This typedef defines what direction the buggy can go in, it is also used to determine what to display.*/
AdrianClarke 0:4aa6e1498925 30 typedef enum {
AdrianClarke 0:4aa6e1498925 31 Up,
AdrianClarke 0:4aa6e1498925 32 Down,
AdrianClarke 0:4aa6e1498925 33 Left,
AdrianClarke 0:4aa6e1498925 34 Right,
AdrianClarke 0:4aa6e1498925 35 TopLeft,
AdrianClarke 0:4aa6e1498925 36 TopRight,
AdrianClarke 0:4aa6e1498925 37 BottomLeft,
AdrianClarke 0:4aa6e1498925 38 BottomRight,
AdrianClarke 0:4aa6e1498925 39 Stop,
AdrianClarke 0:4aa6e1498925 40 Clear,
AdrianClarke 0:4aa6e1498925 41 }Direction;
AdrianClarke 0:4aa6e1498925 42
AdrianClarke 0:4aa6e1498925 43 /* these are function prototypes that declare all the functions
AdrianClarke 0:4aa6e1498925 44 in the library.*/
AdrianClarke 0:4aa6e1498925 45 extern void forward(float); //Move the buggy forward for (float) seconds
AdrianClarke 0:4aa6e1498925 46 extern void left(float); //Turn left for (float) seconds
AdrianClarke 0:4aa6e1498925 47 extern void right(float); //Turn right for (float) seconds
AdrianClarke 0:4aa6e1498925 48 extern void hold(float); //Hold the buggy in an idle state for (float) seconds
AdrianClarke 0:4aa6e1498925 49 extern void bear_Right(float); // Turns the buggy to the right while moving forward
AdrianClarke 0:4aa6e1498925 50 extern void bear_Left(float); // Turns the buggy to the left while moving forward
AdrianClarke 0:4aa6e1498925 51 extern void stop(); //Stop all motors
AdrianClarke 0:4aa6e1498925 52 extern void follow_Line(float);
AdrianClarke 0:4aa6e1498925 53 extern void follow_Line();
AdrianClarke 0:4aa6e1498925 54
AdrianClarke 0:4aa6e1498925 55 extern void readButton(float); //Similar to hold, but scans for button presses while waiting
AdrianClarke 0:4aa6e1498925 56 extern int rollDice(); //Randomly generate a number a display it on the seven segment display
AdrianClarke 0:4aa6e1498925 57
AdrianClarke 0:4aa6e1498925 58
AdrianClarke 0:4aa6e1498925 59 /* stop() and rollDice() do not need to be giving a float
AdrianClarke 0:4aa6e1498925 60 to be run unlike the other functions which use a (float)
AdrianClarke 0:4aa6e1498925 61 to know how long they should run for */
AdrianClarke 0:4aa6e1498925 62
AdrianClarke 0:4aa6e1498925 63 #endif // BUGGY_FUNCTIONS_H