Beep RTTL done + ints.
Dependencies: MCP23017 aconno_bsp beep_2
Fork of acd52832_beep_buzzer by
main.cpp@2:bc9245345c12, 2016-09-23 (annotated)
- Committer:
- jurica238814
- Date:
- Fri Sep 23 12:13:42 2016 +0000
- Revision:
- 2:bc9245345c12
- Parent:
- 0:79fc9d7d880f
IO expander ints done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 2:bc9245345c12 | 1 | #include "mbed.h" |
jurica238814 | 0:79fc9d7d880f | 2 | #include "beep.h" |
jurica238814 | 0:79fc9d7d880f | 3 | #include "acd52832_bsp.h" |
jurica238814 | 0:79fc9d7d880f | 4 | #include "notes.h" |
jurica238814 | 2:bc9245345c12 | 5 | #include "MCP23017.h" |
jurica238814 | 2:bc9245345c12 | 6 | |
jurica238814 | 2:bc9245345c12 | 7 | #define CENTER 7 |
jurica238814 | 2:bc9245345c12 | 8 | |
jurica238814 | 0:79fc9d7d880f | 9 | |
jurica238814 | 0:79fc9d7d880f | 10 | |
jurica238814 | 0:79fc9d7d880f | 11 | Beep buzzer(PIN_BUZZER); |
jurica238814 | 2:bc9245345c12 | 12 | //DigitalOut LED (p26); |
jurica238814 | 0:79fc9d7d880f | 13 | DigitalOut RED (PIN_LED_RED); |
jurica238814 | 2:bc9245345c12 | 14 | DigitalOut GREEN (PIN_LED_GREEN); |
jurica238814 | 2:bc9245345c12 | 15 | MCP23017 expdr = MCP23017(PIN_EXP_SDA, PIN_EXP_SCL, TWI_EXPANDER_ADDR); |
jurica238814 | 2:bc9245345c12 | 16 | InterruptIn button(PIN_EXP_INT_A); |
jurica238814 | 2:bc9245345c12 | 17 | InterruptIn button2(p26); |
jurica238814 | 0:79fc9d7d880f | 18 | |
jurica238814 | 0:79fc9d7d880f | 19 | 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"; |
jurica238814 | 0:79fc9d7d880f | 20 | |
jurica238814 | 2:bc9245345c12 | 21 | void toggle(){ |
jurica238814 | 2:bc9245345c12 | 22 | |
jurica238814 | 2:bc9245345c12 | 23 | // Disable ints |
jurica238814 | 2:bc9245345c12 | 24 | /* |
jurica238814 | 2:bc9245345c12 | 25 | char cmd[3]; |
jurica238814 | 2:bc9245345c12 | 26 | cmd[0] = GPINTEN; |
jurica238814 | 2:bc9245345c12 | 27 | cmd[1] = 0x00; |
jurica238814 | 2:bc9245345c12 | 28 | cmd[2] = 0x00; |
jurica238814 | 2:bc9245345c12 | 29 | */ |
jurica238814 | 2:bc9245345c12 | 30 | //i2c.write(addr, cmd, 2); |
jurica238814 | 2:bc9245345c12 | 31 | buzzer.nobeep(); |
jurica238814 | 2:bc9245345c12 | 32 | GREEN = !GREEN; |
jurica238814 | 2:bc9245345c12 | 33 | setInt(); |
jurica238814 | 2:bc9245345c12 | 34 | //i2c.write(TWI_EXPANDER_ADDR, cmd, 3, false); |
jurica238814 | 2:bc9245345c12 | 35 | //expdr.writeRegister(GPINTEN, (unsigned short)0x0000); |
jurica238814 | 2:bc9245345c12 | 36 | |
jurica238814 | 2:bc9245345c12 | 37 | return; |
jurica238814 | 2:bc9245345c12 | 38 | //expdr.write_bit(0, 10); |
jurica238814 | 2:bc9245345c12 | 39 | //wait(0.5); |
jurica238814 | 2:bc9245345c12 | 40 | |
jurica238814 | 2:bc9245345c12 | 41 | |
jurica238814 | 2:bc9245345c12 | 42 | //expdr.readRegister(GPIO); |
jurica238814 | 2:bc9245345c12 | 43 | //expdr.read_bit(CENTER); |
jurica238814 | 2:bc9245345c12 | 44 | //expdr.readRegister(INTCAP); |
jurica238814 | 2:bc9245345c12 | 45 | //wait(0.5); |
jurica238814 | 2:bc9245345c12 | 46 | /* |
jurica238814 | 2:bc9245345c12 | 47 | while (1){ |
jurica238814 | 2:bc9245345c12 | 48 | GREEN = ! GREEN; |
jurica238814 | 2:bc9245345c12 | 49 | wait(0.6); |
jurica238814 | 2:bc9245345c12 | 50 | } |
jurica238814 | 2:bc9245345c12 | 51 | */ |
jurica238814 | 2:bc9245345c12 | 52 | |
jurica238814 | 2:bc9245345c12 | 53 | // Enable ints |
jurica238814 | 2:bc9245345c12 | 54 | //expdr.writeRegister(GPINTEN, (unsigned short)0x0080); |
jurica238814 | 2:bc9245345c12 | 55 | } |
jurica238814 | 2:bc9245345c12 | 56 | |
jurica238814 | 0:79fc9d7d880f | 57 | |
jurica238814 | 0:79fc9d7d880f | 58 | int main(){ |
jurica238814 | 2:bc9245345c12 | 59 | |
jurica238814 | 2:bc9245345c12 | 60 | // Init IO expander |
jurica238814 | 2:bc9245345c12 | 61 | expdr.reset(); //Restarts the expander to return it to default states |
jurica238814 | 2:bc9245345c12 | 62 | expdr.config(0x01F8, 0xFFFF, 0x0000); |
jurica238814 | 2:bc9245345c12 | 63 | wait(0.1); |
jurica238814 | 2:bc9245345c12 | 64 | // Configure interrupts on JOYSTICK_CENTER pin |
jurica238814 | 2:bc9245345c12 | 65 | //expdr.writeRegister(IOCON, (unsigned char)0x26); |
jurica238814 | 2:bc9245345c12 | 66 | expdr.writeRegister(INTCON, (unsigned short)0x00FF); |
jurica238814 | 2:bc9245345c12 | 67 | expdr.writeRegister(DEFVAL, (unsigned short)0x0180); |
jurica238814 | 2:bc9245345c12 | 68 | expdr.writeRegister(GPINTEN, (unsigned short)0x0080); |
jurica238814 | 2:bc9245345c12 | 69 | |
jurica238814 | 2:bc9245345c12 | 70 | button.fall(&toggle); |
jurica238814 | 2:bc9245345c12 | 71 | button.rise(&toggle); |
jurica238814 | 2:bc9245345c12 | 72 | //button2.rise(&toggle); |
jurica238814 | 2:bc9245345c12 | 73 | //button2.fall(&toggle); |
jurica238814 | 0:79fc9d7d880f | 74 | |
jurica238814 | 0:79fc9d7d880f | 75 | RED = 1; |
jurica238814 | 2:bc9245345c12 | 76 | GREEN = 1; |
jurica238814 | 0:79fc9d7d880f | 77 | buzzer.playRttl(song); |
jurica238814 | 0:79fc9d7d880f | 78 | RED = 0; |
jurica238814 | 0:79fc9d7d880f | 79 | |
jurica238814 | 0:79fc9d7d880f | 80 | while(1){ |
jurica238814 | 2:bc9245345c12 | 81 | RED = 0; |
jurica238814 | 0:79fc9d7d880f | 82 | wait(0.1); |
jurica238814 | 2:bc9245345c12 | 83 | RED = 1; |
jurica238814 | 0:79fc9d7d880f | 84 | wait(0.1); |
jurica238814 | 0:79fc9d7d880f | 85 | } |
jurica238814 | 0:79fc9d7d880f | 86 | } |