interrupt copy

Dependencies:   PinDetect Data_Clock_Pair Seeed_Chainable_LED

Revision:
5:54e66ad3c78a
Parent:
4:52eaedac3d65
--- a/main.cpp	Thu Apr 27 16:05:43 2017 -0600
+++ b/main.cpp	Sun May 21 13:02:36 2017 -0600
@@ -1,16 +1,16 @@
 /*
     Copyright (c) 2010 Andy Kirkham
- 
+
     Permission is hereby granted, free of charge, to any person obtaining a copy
     of this software and associated documentation files (the "Software"), to deal
     in the Software without restriction, including without limitation the rights
     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     copies of the Software, and to permit persons to whom the Software is
     furnished to do so, subject to the following conditions:
- 
+
     The above copyright notice and this permission notice shall be included in
     all copies or substantial portions of the Software.
- 
+
     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -24,12 +24,24 @@
 
 #include "mbed.h"
 #include "PinDetect.h"
+#include "SeeedChainableLED.h"
 
-PinDetect  pin ( PD_14 );
-DigitalOut led1( PF_12 );
-DigitalOut led2( PC_0 );
-DigitalOut led3( PC_3 );
-DigitalOut led4( PF_3 );
+PinDetect  pin ( PF_15 );
+DigitalOut chainStatus(LED2);
+DigitalOut pauseStatus(LED3);
+BusOut redLeds( PE_13, PF_14, PE_11, PE_9, PF_13 );
+BusOut notRedLeds ( PF_12, PA_3, PC_0, PC_3, PF_3 );
+DataClockPair iicChainLedsPins(PB_8, PB_9);
+SeeedChainableLED iicChainLeds(iicChainLedsPins);
+bool chainOn;
+bool pause = false;
+
+Thread statusThread;
+void blink() {
+    for(DigitalOut led(LED1);; Thread::wait(1000) ) {
+        led = !led;
+    }
+}
 
 /*
  * Note, the PinDetect can be defined thus:-
@@ -42,49 +54,60 @@
 // C function callbacks follow.
 
 void keyPressed( void ) {
-    led2 = 1;
-    led3 = 0;
-    led4 = 0;
+    if (!pause) {
+        redLeds = ~redLeds;
+        notRedLeds = ~notRedLeds;
+        if(!chainOn) iicChainLeds.set_color_rgb(255, 50, 2);
+        else iicChainLeds.set_color_rgb(0, 0, 0);
+        chainOn = !chainOn;
+        pause = true;
+    }
 }
 
-void keyReleased( void ) {
-    led2 = 0;
-    led3 = 0;
-    led4 = 0;
-}
+/* void keyReleased( void ) { */
+/*     led2 = 0; */
+/*     led3 = 0; */
+/*     led4 = 0; */
+/* } */
 
 void keyPressedHeld( void ) {
-    led3 = 1;
+    pause = false;
 }
-
-void keyReleasedHeld( void ) {
-    led4 = 1;
-}
+/* void keyReleasedHeld( void ) { */
+/*     pause = false; */
+/* } */
 
 // The main program.
 
 int main() {
 
+    statusThread.start(callback(blink));
+
+    iicChainLeds.set_color_rgb(0, 0, 0);
+    chainOn = false;
+    redLeds = 0;
+    notRedLeds = ~0;
+
     pin.mode( PullDown );
     pin.attach_asserted( &keyPressed );
-    pin.attach_deasserted( &keyReleased );
     pin.attach_asserted_held( &keyPressedHeld );
-    
+    pin.setSamplesTillAssert( 10 );
+    pin.setSamplesTillHeld( 10000 );
+    pin.setSampleFrequency(1000); // Defaults to 20ms.
+
     // This callback will often be of little use as it's
     // called after every assertion/deassertion. However,
     // it's provided for completeness. You may find a use
     // for it. If not, just don't attach a callback and it
     // will not activate.
-    pin.attach_deasserted_held( &keyReleasedHeld );
-    
+    /* pin.attach_deasserted_held( &keyReleasedHeld ); */
+
     // You can define how many continuous samples must be
     // asserted before the attach_asserted() function is called.
-    //     pin.setSamplesTillAssert( 10 );
     // This would mean 10 * 20ms debounce time = 200ms.
 
     // You can define how many continuous samples must be
     // asserted before the attach_asserted_held() function is called.
-    //     pin.setSamplesTillHeld( 200 );
     // This would mean 200 * 20ms debounce time = 2seconds.
 
     // By default, "asserted" assumes the pin going high from 0volts to 5volts
@@ -102,11 +125,10 @@
     // Note, if you change the sampling frequency you will probably also
     // want to change the number of samples till assert and held as show
     // above.
-    pin.setSampleFrequency(); // Defaults to 20ms.
 
-    while( 1 ) {
-        led1 = !led1;
-        wait( 0.2 );
+    for(;; Thread::wait(200) ) {
+        chainStatus = chainOn;
+        pauseStatus = pause;
     }
 }