Electronic dice application for the mBuino platform. Notes: The mBuino starts in Demo mode. In Demo mode the LEDs are lighted, showing sweeps and demo rolls. Connect a button or tilt-switch between P0.4 and GND. No soldering required! When the switch is triggered mBuino goes into Roll mode. In Roll mode mBuino starts with rapid flickering LEDs. Each subsequent switch trigger will perform a roll of the dice, of which the result is shown for ten seconds unless the switch is triggered for another roll. To preserve power, Power down mode is entered after inactivity in Demo mode or Roll mode. Press any button to revive.

Dependencies:   mbed

Fork of mBuino_Dice by Valentin Ivanov

mBuino_Dice

The hardware: No soldering required

As you can see in the picture gallery below, this is a very simple mBuino project, requiring only one extra component: a switch such as a push button or a tilt switch.

Push button

The push-button I used fits neatly between P0.4 and GND. By just bending the legs flat to the PCB, the button attached sturdy enough to make a usable connection.

Tilt switch

The tilt switch version is much more fun. No pushing, just a shake to roll the dice! In the tilt switch version two short wires were used to connect the switch. The wires were twisted around the legs of the tilt switch without any soldering! By adjusting the horizontal level of the switch you can make the dice react more sensitively to small movement.

For a production version, I would of course make it all a bit more durable by soldering the connections and using hot glue to keep everything in place. But going that route, I would also want to make a nicely fitting box, perhaps use other LEDs in a traditional dice-eye position and add an on-off switch...

Revision:
6:e52dbebd7465
Parent:
5:e2f89a6f4d6c
--- a/main.cpp	Mon Sep 15 16:35:48 2014 +0000
+++ b/main.cpp	Tue Sep 16 08:19:55 2014 +0000
@@ -5,6 +5,10 @@
 ** Setup requirements: connect any type of switch between P0.4 and GND.
 ** On mBuino P0.4 is close to GND and the two pitch distance is exactly the same as a mini-switch! 
 **
+** 0.1.140916 Using the Outrageous Circuits mBuino platform instead of LPC11U24 (available now)
+**            Renamed LED ports to newly available mBuino LED constants
+**            Earlier power down after dice roll, showing by flashes slowing down
+** 0.1.140915 Energy use in power down mode down to 3 uA, credits: Andy A
 ** 0.1.140910 Power down after one iteration of demo or ten seconds of wating, credits: Andy A
 ** 0.1.140908 Added deep sleep mode after one iteration of demo or ten seconds of wating, credits: Andy A and Erik Olieman
 **            Added explanatory comments and incorporated suggestion by Erik Olieman
@@ -18,7 +22,7 @@
 
 #include "mbed.h"
 
-DigitalOut LED[] = {(P0_7), (P0_8), (P0_2), (P0_20), (P1_19), (P0_17), (P0_23)};// declare 7 LEDs
+DigitalOut LED[] = {(LED1), (LED2), (LED3), (LED4), (LED5), (LED6), (LED7)};// declare 7 LEDs
 
 InterruptIn ActionButton(P0_4);  // declare the input for the button (or for other single switch, such as movement switch). On mBuino P0.4 is close to GND
 AnalogIn RandomIn(P0_14); // use the random noise on this analog input to seed the random generator
@@ -231,13 +235,16 @@
         fButtonPressed=false;
         
         unsigned uTickStop=tWait.read_ms()+10000;
+        float ftDelay=0.01;
         while(!fButtonPressed)
         {   // flash the LEDS to show we wait for a roll call
-            SweepAllLeds(true, 0.01);
-            SweepAllLeds(false, 0.01);
+            SweepAllLeds(true, ftDelay);
+            SweepAllLeds(false, ftDelay);
 
             if(!fButtonPressed && tWait.read_ms()>uTickStop)
                 myPowerDown();   // enter power-down mode when waited for more than 10 seconds without button pressed
+            else
+                ftDelay=(10-((float)uTickStop-tWait.read_ms())/1000)/100;  // make the fast flashes slow down while closer to power down mode
         }
         fButtonPressed=false;
         
@@ -247,10 +254,16 @@
         fButtonPressed=false;
         
         uTickStop=tWait.read_ms()+10000;
+        ftDelay=0.01;
         while(!fButtonPressed && tWait.read_ms()<uTickStop)
-            //wait(0.1);
-            BlinkDiceLed(nDiceValue, 0.2, 0.01);  // to indicate waiting for a new roll, blink the thrown dice value...
+        {
+            BlinkDiceLed(nDiceValue, 0.2, ftDelay);  // to indicate waiting for a new roll, flash the thrown dice value...
+            ftDelay=(10-((float)uTickStop-tWait.read_ms())/1000)/100;  // make the fast flashes slow down while closer to power down mode
+        }
         SwitchAllLeds(false);
+
+        if(!fButtonPressed)
+            myPowerDown();   // enter power-down mode when waited for more than 10 seconds without button pressed
     }
 }