Beep RTTL done + ints.

Dependencies:   MCP23017 aconno_bsp beep_2

Fork of acd52832_beep_buzzer by Jurica Resetar

Revision:
2:bc9245345c12
Parent:
0:79fc9d7d880f
diff -r b8c2672f5bd6 -r bc9245345c12 main.cpp
--- a/main.cpp	Thu Sep 22 18:13:53 2016 +0000
+++ b/main.cpp	Fri Sep 23 12:13:42 2016 +0000
@@ -1,31 +1,86 @@
- 
- #include "mbed.h"
+  #include "mbed.h"
  #include "beep.h"
  #include "acd52832_bsp.h"
  #include "notes.h"
+ #include "MCP23017.h"
+ 
+ #define CENTER 7
+
  
  
  Beep buzzer(PIN_BUZZER);
- DigitalOut LED (p26);
+ //DigitalOut LED (p26);
  DigitalOut RED (PIN_LED_RED);
-   
-
+ DigitalOut GREEN (PIN_LED_GREEN);
+ MCP23017 expdr = MCP23017(PIN_EXP_SDA, PIN_EXP_SCL, TWI_EXPANDER_ADDR);
+ InterruptIn button(PIN_EXP_INT_A);
+ InterruptIn button2(p26);
 
 char *song = "Greensleaves:d=4,o=5,b=140:g,2a#,c6,d.6,8d#6,d6,2c6,a,f.,8g,a,2a#,g,g.,8f,g,2a,f,2d,g,2a#,c6,d.6,8e6,d6,2c6,a,f.,8g,a,a#.,8a,g,f#.,8e,f#,2g";
 
-
+void toggle(){
+    
+    // Disable ints
+    /*
+    char cmd[3];
+    cmd[0] = GPINTEN;
+    cmd[1] = 0x00;
+    cmd[2] = 0x00;
+    */
+    //i2c.write(addr, cmd, 2);
+    buzzer.nobeep();
+    GREEN = !GREEN;
+    setInt();
+    //i2c.write(TWI_EXPANDER_ADDR, cmd, 3, false);
+    //expdr.writeRegister(GPINTEN, (unsigned short)0x0000);
+    
+    return;
+    //expdr.write_bit(0, 10);
+    //wait(0.5);
+    
+    
+    //expdr.readRegister(GPIO);
+    //expdr.read_bit(CENTER);
+    //expdr.readRegister(INTCAP);
+    //wait(0.5);
+    /*
+    while (1){
+        GREEN = ! GREEN;
+        wait(0.6);
+        }
+    */  
+    
+    // Enable ints
+    //expdr.writeRegister(GPINTEN, (unsigned short)0x0080);
+    }
+    
 
 int main(){
+
+  // Init IO expander
+  expdr.reset();                              //Restarts the expander to return it to default states
+  expdr.config(0x01F8, 0xFFFF, 0x0000);
+  wait(0.1);
+  // Configure interrupts on JOYSTICK_CENTER pin 
+  //expdr.writeRegister(IOCON, (unsigned char)0x26);
+  expdr.writeRegister(INTCON, (unsigned short)0x00FF);
+  expdr.writeRegister(DEFVAL, (unsigned short)0x0180);
+  expdr.writeRegister(GPINTEN, (unsigned short)0x0080);
+    
+  button.fall(&toggle);
+  button.rise(&toggle);
+  //button2.rise(&toggle);
+  //button2.fall(&toggle);
   
-  LED = 1;      
   RED = 1;
+  GREEN = 1;
   buzzer.playRttl(song);
   RED = 0;
   
   while(1){
-      LED = 0;
+      RED = 0;
       wait(0.1);
-      LED = 1;
+      RED = 1;
       wait(0.1);
       }
 }
\ No newline at end of file