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:
4:0c3a1b829d8c
Parent:
3:52997a5f2fbc
Child:
5:e2f89a6f4d6c
--- a/main.cpp	Mon Sep 08 10:01:38 2014 +0000
+++ b/main.cpp	Wed Sep 10 10:00:23 2014 +0000
@@ -5,6 +5,7 @@
 ** 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.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
 **            Improved randomness as per suggestion of Andy A
@@ -50,15 +51,21 @@
 
 Timer tWait;    // time used for tickcounts
 
-void myDeepSleep()
-{   // Go into deep sleep to safe power. Use onboard or off-board interrupt triggered button to revive
-    // see http://mbed.org/forum/repo-52552-mBuino_low_power_led_flasher-community/topic/5130/
-    LPC_PMU->PCON = 0x1;
+void myPowerDown(uint8_t uMode=0x02)
+{   // Go into power-down mode (0x2) to safe most power. Use onboard or off-board interrupt triggered button to revive
+    // See https://mbed.org/forum/electronics/topic/5138/
+    // Alternative: Go into deep sleep mode (0x1) to safe less power. Is quicker than power-down. Also revived using onboard button or interrupt.
+    // See http://mbed.org/forum/repo-52552-mBuino_low_power_led_flasher-community/topic/5130/
+    // Power usage (CR3032 battery life):
+    //   Running 13mA (1.5 day) 
+    //   Sleep 7mA (3 days)
+    //   Deep-sleep 480uA (43 days)
+    //   Power-down 120uA (170 days)
+    LPC_PMU->PCON = uMode;     // 0x2 = power down, 0x1 = deep sleep
     SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
     LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
     __WFI();
 }
- 
 
 void SwitchAllLeds(bool fOn)
 {   // switch all leds on or off
@@ -212,7 +219,7 @@
             wait(1);
             
         if(!fButtonPressed)
-            myDeepSleep();   // enter deep sleep after one demo iteration
+            myPowerDown();   // enter dpower-down mode after one demo iteration
     }
     else
     {   // demo mode is ended, roll the dice upon each button press
@@ -226,7 +233,7 @@
             SweepAllLeds(false, 0.01);
 
             if(!fButtonPressed && tWait.read_ms()>uTickStop)
-                myDeepSleep();   // enter deep sleep when waited for more than 10 seconds without button pressed
+                myPowerDown();   // enter power-down mode when waited for more than 10 seconds without button pressed
         }
         fButtonPressed=false;