Noah Harris / Mbed 2 deprecated BluetoothCurtainControl

Dependencies:   Motor mbed-rtos mbed

Committer:
nonoisfirst
Date:
Mon Mar 14 19:51:59 2016 +0000
Revision:
0:f52dea8105ba
First Commit. Code by Noah Harris and Namrata Patel.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nonoisfirst 0:f52dea8105ba 1 #include "mbed.h"
nonoisfirst 0:f52dea8105ba 2 #include "Motor.h"
nonoisfirst 0:f52dea8105ba 3 #include <ctime>
nonoisfirst 0:f52dea8105ba 4 #include <string>
nonoisfirst 0:f52dea8105ba 5 #include <cstdio>
nonoisfirst 0:f52dea8105ba 6 #include "SongPlayer.h"
nonoisfirst 0:f52dea8105ba 7
nonoisfirst 0:f52dea8105ba 8 using namespace std;
nonoisfirst 0:f52dea8105ba 9
nonoisfirst 0:f52dea8105ba 10 DigitalOut led(LED4);
nonoisfirst 0:f52dea8105ba 11 DigitalOut softReset(p12);
nonoisfirst 0:f52dea8105ba 12 Serial blue(p28,p27);
nonoisfirst 0:f52dea8105ba 13 Motor motorA(p21, p19, p17); //pwm, fwd, rev
nonoisfirst 0:f52dea8105ba 14 Motor motorB(p22,p23, p24); //pwm, fwd, rev
nonoisfirst 0:f52dea8105ba 15 Ticker IRflip;
nonoisfirst 0:f52dea8105ba 16 AnalogIn IR(p16);
nonoisfirst 0:f52dea8105ba 17 void motorStop();
nonoisfirst 0:f52dea8105ba 18
nonoisfirst 0:f52dea8105ba 19 DigitalOut led1(LED1);
nonoisfirst 0:f52dea8105ba 20 DigitalOut led2(LED2);
nonoisfirst 0:f52dea8105ba 21 DigitalOut led3(LED3);
nonoisfirst 0:f52dea8105ba 22
nonoisfirst 0:f52dea8105ba 23 ////////////////GLOBALS
nonoisfirst 0:f52dea8105ba 24 clock_t startTime;
nonoisfirst 0:f52dea8105ba 25 clock_t endTime;
nonoisfirst 0:f52dea8105ba 26 string time_str;
nonoisfirst 0:f52dea8105ba 27 int movingMotors = 0;
nonoisfirst 0:f52dea8105ba 28
nonoisfirst 0:f52dea8105ba 29 ///////////////Function init
nonoisfirst 0:f52dea8105ba 30 void writeSD(double seconds);
nonoisfirst 0:f52dea8105ba 31 double readSD();
nonoisfirst 0:f52dea8105ba 32 void reset();
nonoisfirst 0:f52dea8105ba 33 void playSound(char*);
nonoisfirst 0:f52dea8105ba 34 void motorStop();
nonoisfirst 0:f52dea8105ba 35
nonoisfirst 0:f52dea8105ba 36
nonoisfirst 0:f52dea8105ba 37 ///////////////////Functions
nonoisfirst 0:f52dea8105ba 38 void reset()
nonoisfirst 0:f52dea8105ba 39 {
nonoisfirst 0:f52dea8105ba 40 softReset = 1;
nonoisfirst 0:f52dea8105ba 41 wait(.5);
nonoisfirst 0:f52dea8105ba 42 softReset = 0;
nonoisfirst 0:f52dea8105ba 43 }
nonoisfirst 0:f52dea8105ba 44 void motorStop()
nonoisfirst 0:f52dea8105ba 45 {
nonoisfirst 0:f52dea8105ba 46
nonoisfirst 0:f52dea8105ba 47 string str;
nonoisfirst 0:f52dea8105ba 48 if(IR <= .2f)
nonoisfirst 0:f52dea8105ba 49 {
nonoisfirst 0:f52dea8105ba 50 led2 = 1;
nonoisfirst 0:f52dea8105ba 51 endTime = clock();
nonoisfirst 0:f52dea8105ba 52 double seconds = endTime-startTime;
nonoisfirst 0:f52dea8105ba 53 writeSD(seconds);
nonoisfirst 0:f52dea8105ba 54 led3 =1;
nonoisfirst 0:f52dea8105ba 55 wait(0.5);
nonoisfirst 0:f52dea8105ba 56 led = 0;
nonoisfirst 0:f52dea8105ba 57 motorB.speed(0);
nonoisfirst 0:f52dea8105ba 58 motorA.speed(0);
nonoisfirst 0:f52dea8105ba 59 reset();
nonoisfirst 0:f52dea8105ba 60 }
nonoisfirst 0:f52dea8105ba 61 }
nonoisfirst 0:f52dea8105ba 62 double readSD()
nonoisfirst 0:f52dea8105ba 63 {
nonoisfirst 0:f52dea8105ba 64 double seconds= LPC_RTC->GPREG0;
nonoisfirst 0:f52dea8105ba 65 LPC_RTC->GPREG0 = 0;
nonoisfirst 0:f52dea8105ba 66 return seconds;
nonoisfirst 0:f52dea8105ba 67 }
nonoisfirst 0:f52dea8105ba 68
nonoisfirst 0:f52dea8105ba 69 void writeSD(double seconds)
nonoisfirst 0:f52dea8105ba 70 {
nonoisfirst 0:f52dea8105ba 71 LPC_RTC->GPREG0 = seconds;
nonoisfirst 0:f52dea8105ba 72 }
nonoisfirst 0:f52dea8105ba 73 int main()
nonoisfirst 0:f52dea8105ba 74 {
nonoisfirst 0:f52dea8105ba 75 int counter = 1;
nonoisfirst 0:f52dea8105ba 76 char bnum=0;
nonoisfirst 0:f52dea8105ba 77 while(1)
nonoisfirst 0:f52dea8105ba 78 {
nonoisfirst 0:f52dea8105ba 79 if (blue.getc()=='!' && counter == 1)
nonoisfirst 0:f52dea8105ba 80 {
nonoisfirst 0:f52dea8105ba 81 counter--;
nonoisfirst 0:f52dea8105ba 82 if (blue.getc()=='B') //button data
nonoisfirst 0:f52dea8105ba 83 {
nonoisfirst 0:f52dea8105ba 84
nonoisfirst 0:f52dea8105ba 85 bnum = blue.getc(); //button number
nonoisfirst 0:f52dea8105ba 86 if(bnum=='1') //press number 1
nonoisfirst 0:f52dea8105ba 87 {
nonoisfirst 0:f52dea8105ba 88 led1 = 1;
nonoisfirst 0:f52dea8105ba 89 startTime = clock();
nonoisfirst 0:f52dea8105ba 90 IRflip.attach(&motorStop, 0.05);
nonoisfirst 0:f52dea8105ba 91
nonoisfirst 0:f52dea8105ba 92 motorA.speed(1);
nonoisfirst 0:f52dea8105ba 93 motorB.speed(1);
nonoisfirst 0:f52dea8105ba 94 }
nonoisfirst 0:f52dea8105ba 95 else if(bnum == '2') //press number 2
nonoisfirst 0:f52dea8105ba 96 {
nonoisfirst 0:f52dea8105ba 97 motorA.speed(0);
nonoisfirst 0:f52dea8105ba 98 motorB.speed(0);
nonoisfirst 0:f52dea8105ba 99 }
nonoisfirst 0:f52dea8105ba 100 else if(bnum == '3') //rev
nonoisfirst 0:f52dea8105ba 101 {
nonoisfirst 0:f52dea8105ba 102 double sdTime = readSD();
nonoisfirst 0:f52dea8105ba 103 clock_t temp = clock();
nonoisfirst 0:f52dea8105ba 104 double unwind = (sdTime + temp) + (sdTime + temp)* .065;
nonoisfirst 0:f52dea8105ba 105 while((double)clock() <= unwind)
nonoisfirst 0:f52dea8105ba 106 {
nonoisfirst 0:f52dea8105ba 107 motorA.speed(-1);
nonoisfirst 0:f52dea8105ba 108 motorB.speed(-1);
nonoisfirst 0:f52dea8105ba 109 }
nonoisfirst 0:f52dea8105ba 110
nonoisfirst 0:f52dea8105ba 111 motorA.speed(0);
nonoisfirst 0:f52dea8105ba 112 motorB.speed(0);
nonoisfirst 0:f52dea8105ba 113 reset();
nonoisfirst 0:f52dea8105ba 114 }
nonoisfirst 0:f52dea8105ba 115 else if(bnum == '4') //press number 4
nonoisfirst 0:f52dea8105ba 116 {
nonoisfirst 0:f52dea8105ba 117 motorA.speed(0);
nonoisfirst 0:f52dea8105ba 118 motorB.speed(0);
nonoisfirst 0:f52dea8105ba 119 }
nonoisfirst 0:f52dea8105ba 120 }// if 'B'
nonoisfirst 0:f52dea8105ba 121 }//if '!'
nonoisfirst 0:f52dea8105ba 122 }//while
nonoisfirst 0:f52dea8105ba 123 }//main