Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 4DGL-uLCD-SE MCP23S17
main.cpp
- Committer:
- ftsenn
- Date:
- 2017-11-29
- Revision:
- 5:18a4d0822e89
- Parent:
- 2:2ccb5a604e77
- Child:
- 6:0af0e1b40538
File content as of revision 5:18a4d0822e89:
#include "mbed.h"
BusIn rKeys(p16, p17, p18, p19, p20);
BusIn cKeys(p28, p27, p26, p25, p24, p23, p22, p21);
SPI spiLeft(p5, p6, p7); //SI, SO, SCK
SPI spiRight(p11, p12, p13);
char OpcodeLeft = 0x40;
char OpcodeRight = 0x50;
// mbed p15 is connected to ~chipSelect on the MCP23S17
MCP23S17 chipLeft = MCP23S17(spi, p15, OpcodeLeft);
// mbed p16 is connected to ~chipSelect on the MCP23S17
MCP23S17 chipRight = MCP23S17(spi, p16, OpcodeRight);
int main() {
rKeys.mode(PullUp);
cKeys.mode(PullUp);
int rNeeded = 0x0F;
//options: 0001 1110 (0x1E), 0001 1101 (0x1D), 0001 1011 (0x1B), 0001 0111 (0x17), 0000 1111 (0x0F)
int cNeeded = 0xFE;
//options: 1111 1110 (0xFE), 1111 1101 (0xFD), 1111 1011 (0xFB), 1111 0111 (0xF7),
// 1110 1111 (0xEF), 1101 1111 (0xDF), 1011 1111 (0xBF), 0111 1111 (0x7F)
// Set all Port bits to output direction
chipLeft.direction(PORT_A, 0x00);
chipLeft.direction(PORT_B, 0x00);
chipRight.direction(PORT_A, 0x00);
chipRight.direction(PORT_B, 0x00);
//chip.write(PORT_A, 0x00);
while(1) {
//check if it's the correct key
if ((rKeys == rNeeded) & (cKeys == cNeeded)) {
//get next note
//rNeeded =
//cNeeded =
if (cNeeded == 0x00) { //end song with cNeeded = 0x00
//modify uLCD to signify that we're done
break;
}
//modify uLCD
//turn on correct LED
switch (rNeeded) {
case 0x1D:
chipLeft.write(PORT_A, ~cNeeded);
break;
case 0x1B:
chipLeft.write(PORT_B, ~cNeeded);
break;
case 0x17:
chipRight.write(PORT_A, ~cNeeded);
break;
case 0x0F:
chipRight.write(PORT_B, ~cNeeded);
break;
}
}
}
}
