Niels Buch / Mbed 2 deprecated TrapPowerController_v2

Dependencies:   L6470_lib WakeUp mBuino_Sleep mbed

Fork of SleepyCounting by Andy A

Revision:
1:48d96c61d130
Parent:
0:a9faf46beadf
--- a/main.cpp	Sun Sep 28 09:25:24 2014 +0000
+++ b/main.cpp	Sat Oct 24 07:35:52 2015 +0000
@@ -4,54 +4,75 @@
 
 // DeepSleep or PowerDown we need to use the watchdog (via the WakeUp library)
 
-// pick which version to compile, 1 for sleep, 0 for power down
-#define normalSleep 0
-
-#if normalSleep
-
-// code for normal sleep mode:
 #include "mbed.h"
 #include "mBuinoSleep.h"
+#include "WakeUp.h"
+#include "L6470.h"
 
-Ticker OneSecClock;
+//SPI_MOSI is P0.21
+//SPI_MISO is P0.22
+//SPI_SCK is P1.15
+//D10 is CS is P.11 (or another free pin)
+
+//L6470SDC l6470(P0_21,    P0_22,    P1_15, P0_11);
+L6470 Step(P0_21,    P0_22,    P1_15, P0_11, P0_15 );//mosi,miso,sck,#cs,busy(PullUp)
+
+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
 
-void onClock()
+  
+void interruptButtonPressed()
 {
-    NULL; // empty function, just need a place holder here
+       wait(0.5);
+       LEDs = 127;
+       wait(0.5);
+       LEDs = 0;
+       wait(0.5);
+       LEDs = 127;
+       wait(0.5);
+       LEDs = 0;
+       wait(0.5);
+       LEDs = 127;
+       wait(0.5);
+       LEDs = 127;
+       wait(0.5);
+       LEDs = 0;
+       wait(0.5);
+       LEDs = 127;
+       wait(0.5);
+       LEDs = 0;
+       wait(0.5);
+       LEDs = 127;
+ }   
+ 
+void blink(int count, int diode) {
+     int lednr = 1<<diode; 
+     
+     for(int i = 1; i <= count; i++) {
+       LEDs = lednr;
+       wait(0.2);
+       LEDs = 0;
+       wait(0.2);
+               
+       }
+       
+        
 }
-   
+        
 int main ()
 {
-    LEDs = 1;
-
-    OneSecClock.attach(onClock,1);
+    blink(5,0);
+    ActionButton.fall(interruptButtonPressed); // using the fall requires the button to be unpressed before the interrupt is triggered again
+    blink(5,1);
+    WakeUp::calibrate();
+    blink(5,2);
+    Step.Resets();
+    Step.ReleseSW(0,1);//
+    Step.Run(0, 30); 
+    blink(5,3);
 
     while (1) {
         wait(0.1);
-        mBuinoSleep(Sleep);
-        if (LEDs == 127)
-            LEDs = 1;
-        else
-            LEDs = LEDs + 1;
-    }
-}
-
-
-#else
-
-// code for power down mode
-#include "mbed.h"
-#include "mBuinoSleep.h"
-#include "WakeUp.h"
-        
-int main ()
-{
-    WakeUp::calibrate();
-    LEDs = 1;
-
-    while (1) {
-        wait(0.1);
-        WakeUp::set_ms(900);
+        WakeUp::set_ms(1000*5);
         mBuinoSleep(PowerDownWD);
         if (LEDs == 127)
             LEDs = 1;
@@ -59,5 +80,3 @@
             LEDs = LEDs + 1;
     }
 }
-
-#endif
\ No newline at end of file