Abigail Groenenboom
/
Dice
Dice roll
Diff: main.cpp
- Revision:
- 0:68cc55f8a240
- Child:
- 1:8be4a41833fd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 31 09:29:13 2017 +0000 @@ -0,0 +1,47 @@ +#include "mbed.h" + +DigitalOut ledb(LED_BLUE); +DigitalOut ledr(LED_RED); +DigitalOut ledg(LED_GREEN); + +DigitalOut motor1DC(D7); +PwmOut motor1PWM(D6); + +DigitalIn button1(SW2); + +volatile int n = 0; +float t = 1; + + +void Roll() +{ + ledg = 1; // green led off + ledr = 0; // red led on = rolling + + motor1PWM = 1; // motor on -> roll dice + wait(1.5); + motor1PWM = 0; // motor off + + motor1DC = abs(motor1DC-1); // rotate other way next time + + ledr = 1; // red led off + ledb = 0; // blue led on +} + +int main() +{ + motor1DC = 1; + ledb = 1; + ledr = 1; + ledg = 0; + + while (true) { + if(button1==0) + { + Roll(); + wait(t); // wait before next roll to protect motors + ledb = 1; + ledg = 0; // green led on = ready to roll + } + } +} \ No newline at end of file