.
Dependencies: eeprom keypad mbed-rtos mbed
main.cpp
- Committer:
- 583405000008
- Date:
- 2016-12-04
- Revision:
- 0:b4c98e0b828d
File content as of revision 0:b4c98e0b828d:
#include "mbed.h" #include "rtos.h" #include "Keypad.h" #include "eeprom.h" #include "stdlib.h" //EEPROM memory(I2C_SDA,I2C_SCL,0); Serial PC(D1, D0); // Define your own keypad values char Keytable[] = { '1', '2', '3', 'A', // r0 '4', '5', '6', 'B', // r1 '7', '8', '9', 'C', // r2 '*', '0', '#', 'D' // r3 }; // c0 c1 c2 c3 uint32_t Index; uint32_t oldIndex; string arraysong[4][5] ={{"1A", "2A", "3A","4A", "5A"}, {"1B", "2B", "3B","4B", "5B"}, {"1C", "2C", "3C","4C", "5C"}, {"1D", "2D", "3D","4D", "5D"},}; //keep name's songs to random char like; // if user likes, it send "l" /dislikes send "d" / wants to pass send "o" uint32_t cbAfterInput(uint32_t index) { Index = index; return 0; } int randomja(); int numra; // a number gets from randomja() int main() { // r0 r1 r2 r3 c0 c1 c2 c3 Keypad keypad(A5, A4, D2,D3, D4, D5, D6, D7); keypad.attach(&cbAfterInput); keypad.start(); // energize the keypad via c0-c3 while (1) { __wfi(); //printf("Interrupted\r\n"); //PC.printf("Index:%d\n",Index); //PC.printf("oldIndex:%d\n",oldIndex); //wait_ms(1000); while (oldIndex != Index){ PC.printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]); if (Index == 4){ numra = rand()%5; printf("Jibinarak4 %d\n",numra); printf("song is %s\n",arraysong[Index-4][numra]); /* memory.write(1,Index,1); wait_ms(1); memory.write(2,arraysong,100); wait_ms(1); */ Index =0; numra = 0; oldIndex = Index; } else if (Index == 5){ numra = rand()%5; printf("Jibinarak5 %d\n",numra); printf("song is %s\n",arraysong[Index-4][numra]); /* memory.write(3,Index,1); wait_ms(1); memory.write(4,arraysong,100); wait_ms(1); */ Index =0; numra = 0; oldIndex = Index; } else if (Index == 6){ numra = rand()%5; printf("Jibinarak6 %d\n",numra); PC.printf("song is %s\n",arraysong[Index-4][numra]); /* memory.write(5,Index,1); wait_ms(1); memory.write(6,arraysong,100); wait_ms(1); */ Index =0; numra = 0; oldIndex = Index; } else if (Index == 7){ numra = rand()%5; printf("Jibinarak7 %d\n",numra); PC.printf("song is %s\n",arraysong[Index-4][numra]); /* memory.write(7,Index,1); wait_ms(1); memory.write(8,arraysong,100); wait_ms(1); */ Index =0; numra = 0; oldIndex = Index; } else if (Index == 8){ like = 'l'; printf("like : %c\n",like); /* memory.write(9,Index,1); wait_ms(1); memory.write(10,like,1); wait_ms(1); */ oldIndex = Index; } else if (Index == 9){ like = 'd'; printf("like : %c\n",like); /* memory.write(11,Index,1); wait_ms(1); memory.write(12,like,1); wait_ms(1); */ oldIndex = Index; } else if (Index == 10){ like = 'o'; printf("like : %c\n",like); /* memory.write(13,Index,1); wait_ms(1); memory.write(14,like,1); wait_ms(1); */ oldIndex = Index; } else{oldIndex = Index;} } } }