Test fork nhi
Dependencies: SDFileSystem mbed-rtos mbed emic2
Fork of BAT_senior_design by
main.cpp
- Committer:
- aismail1997
- Date:
- 2017-10-18
- Revision:
- 13:b80dde24e9bc
- Parent:
- 11:b302c71e300f
- Child:
- 14:581a3b02f4c3
File content as of revision 13:b80dde24e9bc:
#include "mbed.h"
#include "rtos.h"
#include "wave_player.h"
#include "SDFileSystem.h"
#include "button.h"
// DEFINE I/O
PwmOut myservo(p21);
DigitalIn pb1 (p20);
//AnalogIn linpot(p20);
Serial pc(USBTX, USBRX);
//DigitalOut myled(LED1);
SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
AnalogOut DACout(p26);
wave_player waver(&DACout);
button button1(myservo, pb1);
// INITIALIZE VARIABLES
// add mode, reset buttons
int start = 0;
int submit = 0;
// FIX THIS: button up: state = 2, button halfway: state = 0; button down: state = 1
int state = 2;
// FUNCTIONS
// play a file on the speaker
void playSound(wave_player waver)
{
FILE *wave_file;
wave_file=fopen("/sd/lesson.wav","r");
waver.play(wave_file);
fclose(wave_file);
}
// THREADS
// thread for the custom button
void button_thread()
{
// button was up and is moving down, move servo in
if (pb1 == 1 && state == 2) {
button1.moveServoIn();
state = 1;
}
// button was down and is being pushed again, move servo out
if (pb1 == 1 && state == 1) {
button1.moveServoOut();
state = 2;
}
Thread::wait(200); // wait till thread is done
}
void submit_thread()
{
Thread::wait(500); // wait till thread is done
}
void start_thread()
{
// read pb_start
// if 1
start == 1;
// else 0
Thread::wait(500); // wait till thread is done
}
int main()
{
// SETUP
// pull up the pushbutton to prevent bouncing
pb1.mode(PullUp);
wait(.001);
// servo begins at 30 degrees
// replace with a button setup function
for(int i=0; i<=3; i++) {
myservo = i/100.0;
wait(0.01);
}
// MAIN THREAD
while(true) {
// start threads for reset, mode, start
Thread t1(start_thread);
// setup SDcard and Speaker
// when started
while (start == 0) {}
Thread t2(button_thread);
//Thread t3(submit_thread);
// when submitted
//while (submit == 0) {}
// start button threads and submit thread
// if submit close button threads and submit thread
// check result
// play results on speaker
// save results
// read linear potentiometer
//if (linpot < 0.5) {
//float potval = linpot;
//pc.printf("linear pot: %f\n", potval);
Thread::wait(200); // wait till thread is done
}
}
