Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Motor mbed-rtos mbed
Revision 0:f52dea8105ba, committed 2016-03-14
- Comitter:
- nonoisfirst
- Date:
- Mon Mar 14 19:51:59 2016 +0000
- Commit message:
- First Commit. Code by Noah Harris and Namrata Patel.
Changed in this revision
diff -r 000000000000 -r f52dea8105ba Motor.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor.lib Mon Mar 14 19:51:59 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/simon/code/Motor/#f265e441bcd9
diff -r 000000000000 -r f52dea8105ba main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Mar 14 19:51:59 2016 +0000 @@ -0,0 +1,123 @@ +#include "mbed.h" +#include "Motor.h" +#include <ctime> +#include <string> +#include <cstdio> +#include "SongPlayer.h" + +using namespace std; + +DigitalOut led(LED4); +DigitalOut softReset(p12); +Serial blue(p28,p27); +Motor motorA(p21, p19, p17); //pwm, fwd, rev +Motor motorB(p22,p23, p24); //pwm, fwd, rev +Ticker IRflip; +AnalogIn IR(p16); +void motorStop(); + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); + +////////////////GLOBALS +clock_t startTime; +clock_t endTime; +string time_str; +int movingMotors = 0; + +///////////////Function init +void writeSD(double seconds); +double readSD(); +void reset(); +void playSound(char*); +void motorStop(); + + +///////////////////Functions +void reset() +{ + softReset = 1; + wait(.5); + softReset = 0; +} +void motorStop() +{ + + string str; + if(IR <= .2f) + { + led2 = 1; + endTime = clock(); + double seconds = endTime-startTime; + writeSD(seconds); + led3 =1; + wait(0.5); + led = 0; + motorB.speed(0); + motorA.speed(0); + reset(); + } +} +double readSD() +{ + double seconds= LPC_RTC->GPREG0; + LPC_RTC->GPREG0 = 0; + return seconds; +} + +void writeSD(double seconds) +{ + LPC_RTC->GPREG0 = seconds; +} +int main() +{ + int counter = 1; + char bnum=0; + while(1) + { + if (blue.getc()=='!' && counter == 1) + { + counter--; + if (blue.getc()=='B') //button data + { + + bnum = blue.getc(); //button number + if(bnum=='1') //press number 1 + { + led1 = 1; + startTime = clock(); + IRflip.attach(&motorStop, 0.05); + + motorA.speed(1); + motorB.speed(1); + } + else if(bnum == '2') //press number 2 + { + motorA.speed(0); + motorB.speed(0); + } + else if(bnum == '3') //rev + { + double sdTime = readSD(); + clock_t temp = clock(); + double unwind = (sdTime + temp) + (sdTime + temp)* .065; + while((double)clock() <= unwind) + { + motorA.speed(-1); + motorB.speed(-1); + } + + motorA.speed(0); + motorB.speed(0); + reset(); + } + else if(bnum == '4') //press number 4 + { + motorA.speed(0); + motorB.speed(0); + } + }// if 'B' + }//if '!' + }//while +}//main \ No newline at end of file
diff -r 000000000000 -r f52dea8105ba mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Mon Mar 14 19:51:59 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#f62a48e9da94
diff -r 000000000000 -r f52dea8105ba mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Mar 14 19:51:59 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb \ No newline at end of file