Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int DELAY = 500;
- enum T_Note {
- C4,
- D,
- E,
- F,
- G,
- A,
- B,
- C5,
- PAUSE,
- };
- const byte KEY = A0;
- const byte MODE = 6;
- const byte SOUNDER = 7;const int DELAY = 500;
- enum T_Note {
- C4,
- D,
- E,
- F,
- G,
- A,
- B,
- C5,
- PAUSE,
- };
- const byte KEY = A0;
- const byte MODE = 6;
- const byte SOUNDER = 7;
- const byte LED_REC;
- const byte LED_PLAY;
- const byte LCD_D4 = 10;
- const byte LCD_D5 = 11;
- const byte LCD_D6 = 12;
- const byte LCD_D7 = 13;
- const byte LCD_E = 9;
- const byte LCD_RS = 8;
- const int notes[] = {262, 294, 330, 349, 392, 440, 494, 523, 0};
- const int NUM_OF_NOTES = PAUSE; //PAUSE is the last enum value of Note
- const float noteRanges[NUM_OF_NOTES][2] = {
- {0.100, 0.459},
- {0.460, 0.842},
- {0.843, 1.218},
- {1.219, 1.599},
- {1.600, 1.910},
- {1.911, 2.139},
- {2.140, 2.377},
- {2.378, 3.000}
- };
- float convToV(int in)
- {
- return in * (5.0/1023);
- }
- int notePressed(float note)
- {
- for(size_t i = 0; i < NUM_OF_NOTES; i++)
- {
- if(note >= noteRanges[i][0] && note <= noteRanges[i][1])
- {
- return i;
- }
- }
- return PAUSE;
- }
- void setup()
- {
- Serial.begin(9600);
- pinMode(KEY, INPUT);
- }
- void loop()
- {
- float in = convToV(analogRead(KEY));//input voltage
- Serial.print(in);
- switch(notePressed(in))
- {
- case C4:
- Serial.println(" C4 ");
- break;
- case D:
- Serial.println(" D ");
- break;
- case E:
- Serial.println(" E ");
- break;
- case F:
- Serial.println(" F ");
- break;
- case G:
- Serial.println(" G ");
- break;
- case A:
- Serial.println(" A ");
- break;
- case B:
- Serial.println(" B ");
- break;
- case C5:
- Serial.println(" C5 ");
- break;
- case PAUSE:
- Serial.println(" PPause ");
- }
- delay(DELAY);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement