Beep RTTL done + ints.

Dependencies:   MCP23017 aconno_bsp beep_2

Fork of acd52832_beep_buzzer by Jurica Resetar

Files at this revision

API Documentation at this revision

Comitter:
jurica238814
Date:
Fri Sep 23 12:13:42 2016 +0000
Parent:
1:b8c2672f5bd6
Commit message:
IO expander ints done

Changed in this revision

MCP23017.lib Show annotated file Show diff for this revision Revisions of this file
aconno_bsp.lib Show annotated file Show diff for this revision Revisions of this file
beep.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b8c2672f5bd6 -r bc9245345c12 MCP23017.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP23017.lib	Fri Sep 23 12:13:42 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/jurica238814/code/MCP23017/#2e65b7f39273
diff -r b8c2672f5bd6 -r bc9245345c12 aconno_bsp.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aconno_bsp.lib	Fri Sep 23 12:13:42 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/jurica238814/code/aconno_bsp/#6d9c6c231034
diff -r b8c2672f5bd6 -r bc9245345c12 beep.lib
--- a/beep.lib	Thu Sep 22 18:13:53 2016 +0000
+++ b/beep.lib	Fri Sep 23 12:13:42 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/jurica238814/code/beep/#49c961e79a12
+https://developer.mbed.org/users/jurica238814/code/beep_2/#936ba3699e47
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