Working read code with mode button

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Testnew by BAT

Committer:
aismail1997
Date:
Fri Oct 13 15:01:03 2017 +0000
Revision:
8:1aa86ad19af9
Parent:
6:cc181f8f2bd1
Child:
11:418a4437a693
rtos failing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aismail1997 2:9eda4611081a 1 #include "mbed.h"
aismail1997 8:1aa86ad19af9 2 #include "functions.cpp"
aismail1997 8:1aa86ad19af9 3 #include "rtos.h"
aismail1997 5:9ed43e974156 4
aismail1997 2:9eda4611081a 5 PwmOut myservo(p21);
aismail1997 2:9eda4611081a 6 DigitalIn pb1 (p20);
aismail1997 2:9eda4611081a 7 //AnalogIn linpot(p20);
aismail1997 2:9eda4611081a 8 Serial pc(USBTX, USBRX);
aismail1997 6:cc181f8f2bd1 9 //DigitalOut myled(LED1);
aismail1997 6:cc181f8f2bd1 10 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
aismail1997 6:cc181f8f2bd1 11 AnalogOut DACout(p26);
aismail1997 6:cc181f8f2bd1 12 wave_player waver(&DACout);
aismail1997 6:cc181f8f2bd1 13
aismail1997 8:1aa86ad19af9 14 // add start, mode, reset buttons
aismail1997 8:1aa86ad19af9 15
aismail1997 8:1aa86ad19af9 16
aismail1997 8:1aa86ad19af9 17
aismail1997 8:1aa86ad19af9 18
aismail1997 8:1aa86ad19af9 19 // THREADS
aismail1997 8:1aa86ad19af9 20
aismail1997 8:1aa86ad19af9 21
aismail1997 8:1aa86ad19af9 22 void button_thread()
aismail1997 6:cc181f8f2bd1 23 {
aismail1997 8:1aa86ad19af9 24
aismail1997 6:cc181f8f2bd1 25 }
aismail1997 6:cc181f8f2bd1 26
aismail1997 8:1aa86ad19af9 27 void submit_thread()
aismail1997 6:cc181f8f2bd1 28 {
aismail1997 8:1aa86ad19af9 29
aismail1997 6:cc181f8f2bd1 30 }
aismail1997 6:cc181f8f2bd1 31
aismail1997 8:1aa86ad19af9 32 void start_thread()
aismail1997 6:cc181f8f2bd1 33 {
aismail1997 8:1aa86ad19af9 34 // read pb_start
aismail1997 8:1aa86ad19af9 35 // if 1
aismail1997 8:1aa86ad19af9 36 start == 1;
aismail1997 8:1aa86ad19af9 37 // else 0
aismail1997 6:cc181f8f2bd1 38 }
aismail1997 2:9eda4611081a 39
aismail1997 2:9eda4611081a 40 int main()
aismail1997 2:9eda4611081a 41 {
aismail1997 8:1aa86ad19af9 42 // SETUP
aismail1997 2:9eda4611081a 43 // button up: state = 0, button halfway: state = 1; button down: state = 2
aismail1997 2:9eda4611081a 44 int state = 2;
aismail1997 6:cc181f8f2bd1 45 // pull up the pushbutton to prevent bouncing
aismail1997 2:9eda4611081a 46 pb1.mode(PullUp);
aismail1997 2:9eda4611081a 47 wait(.001);
aismail1997 6:cc181f8f2bd1 48 // servo begins at 30 degrees
aismail1997 2:9eda4611081a 49 for(int i=0; i<=3; i++) {
aismail1997 2:9eda4611081a 50 myservo = i/100.0;
aismail1997 2:9eda4611081a 51 wait(0.01);
aismail1997 2:9eda4611081a 52 }
aismail1997 6:cc181f8f2bd1 53
aismail1997 8:1aa86ad19af9 54 // MAIN THREAD
aismail1997 8:1aa86ad19af9 55 while(true) {
aismail1997 8:1aa86ad19af9 56
aismail1997 8:1aa86ad19af9 57 // start threads for reset, mode, start
aismail1997 8:1aa86ad19af9 58 Thread t1(start_thread);
aismail1997 8:1aa86ad19af9 59
aismail1997 8:1aa86ad19af9 60 // setup SDcard and Speaker
aismail1997 8:1aa86ad19af9 61
aismail1997 8:1aa86ad19af9 62
aismail1997 8:1aa86ad19af9 63 // when started
aismail1997 8:1aa86ad19af9 64 while (start == 0) {}
aismail1997 8:1aa86ad19af9 65 Thread t2(button_thread);
aismail1997 8:1aa86ad19af9 66 Thread t3(submit_thread);
aismail1997 8:1aa86ad19af9 67
aismail1997 8:1aa86ad19af9 68 // when submitted
aismail1997 8:1aa86ad19af9 69 while (submit == 0) {}
aismail1997 8:1aa86ad19af9 70
aismail1997 8:1aa86ad19af9 71
aismail1997 8:1aa86ad19af9 72 // start button threads and submit thread
aismail1997 8:1aa86ad19af9 73 // if submit close button threads and submit thread
aismail1997 8:1aa86ad19af9 74 // check result, speaker result
aismail1997 8:1aa86ad19af9 75 // save results
aismail1997 8:1aa86ad19af9 76
aismail1997 8:1aa86ad19af9 77
aismail1997 8:1aa86ad19af9 78
aismail1997 8:1aa86ad19af9 79
aismail1997 2:9eda4611081a 80 // Servo code
aismail1997 2:9eda4611081a 81 if (pb1 == 1 && state == 2) {
aismail1997 8:1aa86ad19af9 82 moveServoIn(myservo, pb1);
aismail1997 2:9eda4611081a 83 state = 1;
aismail1997 2:9eda4611081a 84 }
aismail1997 2:9eda4611081a 85 // rotate 90 degrees other way
aismail1997 2:9eda4611081a 86 if (pb1 == 1 && state == 1) {
aismail1997 8:1aa86ad19af9 87 moveServoOut(myservo, pb1);
aismail1997 2:9eda4611081a 88 state = 2;
aismail1997 2:9eda4611081a 89 }
aismail1997 6:cc181f8f2bd1 90
aismail1997 6:cc181f8f2bd1 91 // SD card code
aismail1997 6:cc181f8f2bd1 92
aismail1997 6:cc181f8f2bd1 93 // speaker code
aismail1997 2:9eda4611081a 94
aismail1997 2:9eda4611081a 95 // read linear potentiometer
aismail1997 2:9eda4611081a 96 //if (linpot < 0.5) {
aismail1997 2:9eda4611081a 97 //float potval = linpot;
aismail1997 2:9eda4611081a 98 //pc.printf("linear pot: %f\n", potval);
aismail1997 2:9eda4611081a 99 }
aismail1997 2:9eda4611081a 100 }