RenBuggyTimed with edited function and access to seven segment display

Dependencies:   SevenSegmentDisplay mbed

Fork of 1-RenBuggyTimed by Ren Buggy

Files at this revision

API Documentation at this revision

Comitter:
DanArgust
Date:
Wed Apr 13 07:04:28 2016 +0000
Parent:
0:9870f526ddd1
Commit message:
Release 0.0.1 1-RenBuggyTimed with changes all functions and including access to Seven Segment Display

Changed in this revision

SevenSegmentDisplay.lib Show annotated file Show diff for this revision Revisions of this file
TimedMovement.cpp Show annotated file Show diff for this revision Revisions of this file
TimedMovement.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SevenSegmentDisplay.lib	Wed Apr 13 07:04:28 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/jf1452/code/SevenSegmentDisplay/#cb7339a2e196
--- a/TimedMovement.cpp	Fri Mar 11 10:36:38 2016 +0000
+++ b/TimedMovement.cpp	Wed Apr 13 07:04:28 2016 +0000
@@ -1,6 +1,6 @@
 /*********************************************************
 *TimedMovement.cpp                                       *
-*Author: Elijah Orr                                      *
+*Author: Dan Argust                                      *
 *                                                        *  
 *A library of functions that can be used to control the  * 
 *RenBuggy.                                               *
@@ -12,6 +12,7 @@
 /* necessary includes */
 #include "mbed.h"
 #include "TimedMovement.h"
+#include "SevenSegmentDisplay.h"
 
 /* PwmOut is a class included in the mbed.h library that allows
 a pin to be configured as a PWM output. This is used to control
@@ -21,6 +22,11 @@
 PwmOut Lmotor(LeftMotorPin);
 PwmOut Rmotor(RightMotorPin);
 
+DigitalIn CurrentButtonState(p7);
+bool LastButtonState = 0;
+
+SevenSegmentDisplay seg(0);
+
 /* Function definitions contain the code that will execute when 
 the function is called. These must have the same return type
 and parameters as the function declarations. */
@@ -35,16 +41,31 @@
 *                                                               *
 * Returns: none                                                 *
 ****************************************************************/
+extern void hold(float time)
+{
+    seg.DisplayDigits(0,0);
+    for (float i = time;i>0;i-=0.01){
+        seg.DisplayDigits((int)i/10,(int)i%10);
+        //if (CurrentButtonState == 1 and LastButtonState == 0){
+        //    rollDice();
+        //}
+        //LastButtonState = CurrentButtonState;
+        wait(0.01);
+    }
+}
+
 extern void forward(float time)
 {
     /* Lmotor and Rmotor are set to 1.0 (i.e. the motors will 
     operate at full speed). As both motors will move at the 
     same speed, the RenBuggy will go directly forward. */
+    //Lmotor = Rmotor = 1.0;
     Lmotor = Rmotor = 1.0;
     /* the program will wait here for the length of time passed 
-    to the function before continuing. wait() is a function 
-    provided from mbed.h; a loop could be used instead. */
-    wait(time);
+    to the function before continuing. hold() is used to wait a
+    number of seconds and display them on the seven seg display */
+    hold(time);
+    stop();
 }
 
 /****************************************************************
@@ -60,8 +81,10 @@
 extern void left(float time)
 {
     Rmotor = 1.0;
-    Lmotor = 0.2;
-    wait(time);
+    Lmotor = 0.0;
+    hold(time);
+    //readButton(time);
+    stop();
 }
 
 /****************************************************************
@@ -77,8 +100,9 @@
 extern void right(float time)
 {
     Lmotor = 1.0;
-    Rmotor = 0.2;
-    wait(time);
+    Rmotor = 0.0;
+    hold(time);
+    stop();
 }
 
 /****************************************************************
@@ -95,4 +119,31 @@
     Lmotor = Rmotor = 0;
 }
 
+extern void readButton(float time)
+{
+    seg.DisplayDigits(0,0);
+    for (float i = time;i>0;i-=0.01)
+    {
+        if (CurrentButtonState == 1 and LastButtonState == 0){
+            rollDice();
+            //stop();
+            //right(2.0);
+        }
+        LastButtonState = CurrentButtonState;
+        wait(0.01);
+    }
+}
+
+extern int rollDice()
+{
+    int tens;
+    int units;
+    for (int i = 20;i>0;i--){
+        tens = rand()%9;
+        units = rand()%9;
+        seg.DisplayDigits(tens,units);
+        wait(0.04);
+    }
+    return tens*10+units;
+}
 #endif // TIMEDMOVEMENT_C
\ No newline at end of file
--- a/TimedMovement.h	Fri Mar 11 10:36:38 2016 +0000
+++ b/TimedMovement.h	Wed Apr 13 07:04:28 2016 +0000
@@ -31,9 +31,13 @@
 extern void forward(float);
 extern void left(float);
 extern void right(float);
+extern void hold(float);
+extern void stop();
+
+extern void readButton(float);
+extern int rollDice();
 /* stop() is slightly different in that it doesn't expect to be passed
 any variables, so the parentheses can be left empty. Passing a variable
 to this function would cause an error */
-extern void stop();
 
 #endif // TIMEDMOVEMENT_H
\ No newline at end of file
--- a/main.cpp	Fri Mar 11 10:36:38 2016 +0000
+++ b/main.cpp	Wed Apr 13 07:04:28 2016 +0000
@@ -1,6 +1,6 @@
 /*********************************************************
 *RenBuggyTimed                                           *
-*Author: Elijah Orr                                      *
+*Author: Dan Argust                                      *
 *                                                        *  
 *This program demonstates use of a library of functions  *
 *(TimedMovement) to control the movement of the RenBuggy.*
@@ -33,8 +33,22 @@
     and TimedMovement.cpp, and specify the length of time we want
     them to run for by passing a variable which represents a 
     length of time in seconds */
-    forward(5);
+    forward(5.5);
+    hold(16);
+    readButton(11);
+    forward(3);
     left(2);
-    forward(5);
-    stop();
-}
+    right(6.5);
+    forward(3);
+    hold(5);
+    
+    right(0.25);
+    for (int i = 0;i<6;i++)
+    {
+        left(0.5);
+        right(0.5);
+    }
+    left(0.25);
+    forward(1.0);
+    
+}
\ No newline at end of file