|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
-
-
-
-
-
-
-
-
-
-
-
-
- #include <Audio.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <SD.h>
- #include <SerialFlash.h>
-
-
-
-
- AudioInputI2S audioIn;
- AudioAnalyzeToneDetect row1;
- AudioAnalyzeToneDetect row2;
- AudioAnalyzeToneDetect row3;
- AudioAnalyzeToneDetect row4;
- AudioAnalyzeToneDetect column1;
- AudioAnalyzeToneDetect column2;
- AudioAnalyzeToneDetect column3;
- AudioSynthWaveformSine sine1;
- AudioSynthWaveformSine sine2;
- AudioMixer4 mixer;
- AudioOutputI2S audioOut;
-
-
-
- AudioConnection patchCord01(audioIn, 0, row1, 0);
- AudioConnection patchCord02(audioIn, 0, row2, 0);
- AudioConnection patchCord03(audioIn, 0, row3, 0);
- AudioConnection patchCord04(audioIn, 0, row4, 0);
- AudioConnection patchCord05(audioIn, 0, column1, 0);
- AudioConnection patchCord06(audioIn, 0, column2, 0);
- AudioConnection patchCord07(audioIn, 0, column3, 0);
- AudioConnection patchCord10(sine1, 0, mixer, 0);
- AudioConnection patchCord11(sine2, 0, mixer, 1);
- AudioConnection patchCord12(mixer, 0, audioOut, 0);
- AudioConnection patchCord13(mixer, 0, audioOut, 1);
-
-
-
- AudioControlSGTL5000 audioShield;
-
-
- void setup() {
-
-
- AudioMemory(12);
-
-
- audioShield.enable();
- audioShield.volume(0.5);
-
- while (!Serial) ;
- delay(100);
-
-
-
-
- row1.frequency(697, 21);
- row2.frequency(770, 23);
- row3.frequency(852, 25);
- row4.frequency(941, 28);
- column1.frequency(1209, 36);
- column2.frequency(1336, 40);
- column3.frequency(1477, 44);
- }
-
- const float row_threshold = 0.2;
- const float column_threshold = 0.2;
-
- void loop() {
- float r1, r2, r3, r4, c1, c2, c3;
- char digit=0;
-
-
- r1 = row1.read();
- r2 = row2.read();
- r3 = row3.read();
- r4 = row4.read();
- c1 = column1.read();
- c2 = column2.read();
- c3 = column3.read();
-
-
- Serial.print("tones: ");
- Serial.print(r1);
- Serial.print(", ");
- Serial.print(r2);
- Serial.print(", ");
- Serial.print(r3);
- Serial.print(", ");
- Serial.print(r4);
- Serial.print(", ");
- Serial.print(c1);
- Serial.print(", ");
- Serial.print(c2);
- Serial.print(", ");
- Serial.print(c3);
-
-
- if (r1 >= row_threshold) {
- if (c1 > column_threshold) {
- digit = '1';
- } else if (c2 > column_threshold) {
- digit = '2';
- } else if (c3 > column_threshold) {
- digit = '3';
- }
- } else if (r2 >= row_threshold) {
- if (c1 > column_threshold) {
- digit = '4';
- } else if (c2 > column_threshold) {
- digit = '5';
- } else if (c3 > column_threshold) {
- digit = '6';
- }
- } else if (r3 >= row_threshold) {
- if (c1 > column_threshold) {
- digit = '7';
- } else if (c2 > column_threshold) {
- digit = '8';
- } else if (c3 > column_threshold) {
- digit = '9';
- }
- } else if (r4 >= row_threshold) {
- if (c1 > column_threshold) {
- digit = '*';
- } else if (c2 > column_threshold) {
- digit = '0';
- } else if (c3 > column_threshold) {
- digit = '#';
- }
- }
-
-
- if (digit > 0) {
- Serial.print(" --> Key: ");
- Serial.print(digit);
- }
- Serial.println();
-
-
-
-
-
-
-
-
-
-
- if (Serial.available()) {
- char key = Serial.read();
- int low=0;
- int high=0;
- if (key == '1') {
- low = 697;
- high = 1209;
- } else if (key == '2') {
- low = 697;
- high = 1336;
- } else if (key == '3') {
- low = 697;
- high = 1477;
- } else if (key == '4') {
- low = 770;
- high = 1209;
- } else if (key == '5') {
- low = 770;
- high = 1336;
- } else if (key == '6') {
- low = 770;
- high = 1477;
- } else if (key == '7') {
- low = 852;
- high = 1209;
- } else if (key == '8') {
- low = 852;
- high = 1336;
- } else if (key == '9') {
- low = 852;
- high = 1477;
- } else if (key == '*') {
- low = 941;
- high = 1209;
- } else if (key == '0') {
- low = 941;
- high = 1336;
- } else if (key == '#') {
- low = 941;
- high = 1477;
- }
-
-
- if (low > 0 && high > 0) {
- Serial.print("Output sound for key ");
- Serial.print(key);
- Serial.print(", low freq=");
- Serial.print(low);
- Serial.print(", high freq=");
- Serial.print(high);
- Serial.println();
- AudioNoInterrupts();
- sine1.frequency(low);
- sine1.amplitude(0.4);
- sine2.frequency(high);
- sine2.amplitude(0.45);
- AudioInterrupts();
- delay(100);
- AudioNoInterrupts();
- sine1.amplitude(0);
- sine2.amplitude(0);
- AudioInterrupts();
- delay(50);
- }
- }
-
- delay(25);
- }
-
-
|