Abigail Groenenboom
/
Dice
Dice roll
Diff: main.cpp
- Revision:
- 2:0432dad1e3ac
- Parent:
- 1:8be4a41833fd
diff -r 8be4a41833fd -r 0432dad1e3ac main.cpp --- a/main.cpp Wed Nov 01 09:17:20 2017 +0000 +++ b/main.cpp Fri Nov 03 10:34:30 2017 +0000 @@ -1,16 +1,17 @@ #include "mbed.h" +// Led control outputs DigitalOut ledb(LED_BLUE); DigitalOut ledr(LED_RED); DigitalOut ledg(LED_GREEN); +// Motor control outputs DigitalOut motor1DC(D7); PwmOut motor1PWM(D6); +// Input signals. Can either be pressing switch2 or EMG control. DigitalIn button1(SW2); - -volatile int n = 0; -float t = 1; +AnalogIn EMGDice(A0); void Roll() { @@ -18,30 +19,34 @@ ledr = 0; // red led on = rolling motor1PWM = 1; // motor on -> roll dice - wait(1.5); + wait(1.05); motor1PWM = 0; // motor off motor1DC = abs(motor1DC-1); // rotate other way next time ledr = 1; // red led off - ledb = 0; // blue led on + ledb = 0; // blue led on -> inidcates wait time to protect motors } int main() { + // Initialize system motor1DC = 1; ledb = 1; ledr = 1; ledg = 0; + float t = 1.5; // Wait time (s) between rolls to protect motor + // Dice roll code while (true) { - if(button1==0) + if(button1==0 or EMGDice>0.8) // Roll dice if switch2 is pressed or EMG input is delivered. { Roll(); wait(t); // wait before next roll to protect motors - ledb = 1; + ledb = 1; ledg = 0; // green led on = ready to roll - } + } + } } \ No newline at end of file