|
-
-
-
-
-
-
-
-
- #include <Audio.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <SD.h>
- #include <SerialFlash.h>
-
-
-
-
- AudioInputAnalog audioIn;
- AudioAnalyzeToneDetect row1;
- AudioAnalyzeToneDetect row2;
- AudioAnalyzeToneDetect row3;
- AudioAnalyzeToneDetect row4;
- AudioAnalyzeToneDetect column1;
- AudioAnalyzeToneDetect column2;
- AudioAnalyzeToneDetect column3;
-
-
-
- AudioConnection patchCord1(audioIn, 0, row1, 0);
- AudioConnection patchCord2(audioIn, 0, row2, 0);
- AudioConnection patchCord3(audioIn, 0, row3, 0);
- AudioConnection patchCord4(audioIn, 0, row4, 0);
- AudioConnection patchCord5(audioIn, 0, column1, 0);
- AudioConnection patchCord6(audioIn, 0, column2, 0);
- AudioConnection patchCord7(audioIn, 0, column3, 0);
-
-
- const int sevenseg_a = 17;
- const int sevenseg_b = 9;
- const int sevenseg_c = 11;
- const int sevenseg_d = 12;
- const int sevenseg_e = 14;
- const int sevenseg_f = 15;
- const int sevenseg_g = 10;
-
-
- void setup() {
-
-
- AudioMemory(3);
-
-
-
-
-
-
-
- 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);
-
-
-
-
-
-
- pinMode(sevenseg_a, OUTPUT);
- pinMode(sevenseg_b, OUTPUT);
- pinMode(sevenseg_c, OUTPUT);
- pinMode(sevenseg_d, OUTPUT);
- pinMode(sevenseg_e, OUTPUT);
- pinMode(sevenseg_f, OUTPUT);
- pinMode(sevenseg_g, OUTPUT);
- digitalWrite(sevenseg_a, HIGH);
- digitalWrite(sevenseg_b, HIGH);
- digitalWrite(sevenseg_c, HIGH);
- digitalWrite(sevenseg_d, HIGH);
- digitalWrite(sevenseg_e, HIGH);
- digitalWrite(sevenseg_f, HIGH);
- digitalWrite(sevenseg_g, HIGH);
- }
-
- 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';
- digitalWrite(sevenseg_a, HIGH);
- digitalWrite(sevenseg_b, LOW);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, HIGH);
- digitalWrite(sevenseg_e, HIGH);
- digitalWrite(sevenseg_f, HIGH);
- digitalWrite(sevenseg_g, HIGH);
- } else if (c2 > column_threshold) {
- digit = '2';
- digitalWrite(sevenseg_a, LOW);
- digitalWrite(sevenseg_b, LOW);
- digitalWrite(sevenseg_c, HIGH);
- digitalWrite(sevenseg_d, LOW);
- digitalWrite(sevenseg_e, LOW);
- digitalWrite(sevenseg_f, HIGH);
- digitalWrite(sevenseg_g, LOW);
- } else if (c3 > column_threshold) {
- digit = '3';
- digitalWrite(sevenseg_a, LOW);
- digitalWrite(sevenseg_b, LOW);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, LOW);
- digitalWrite(sevenseg_e, HIGH);
- digitalWrite(sevenseg_f, HIGH);
- digitalWrite(sevenseg_g, LOW);
- }
- } else if (r2 >= row_threshold) {
- if (c1 > column_threshold) {
- digit = '4';
- digitalWrite(sevenseg_a, HIGH);
- digitalWrite(sevenseg_b, LOW);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, HIGH);
- digitalWrite(sevenseg_e, HIGH);
- digitalWrite(sevenseg_f, LOW);
- digitalWrite(sevenseg_g, LOW);
- } else if (c2 > column_threshold) {
- digit = '5';
- digitalWrite(sevenseg_a, LOW);
- digitalWrite(sevenseg_b, HIGH);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, LOW);
- digitalWrite(sevenseg_e, HIGH);
- digitalWrite(sevenseg_f, LOW);
- digitalWrite(sevenseg_g, LOW);
- } else if (c3 > column_threshold) {
- digit = '6';
- digitalWrite(sevenseg_a, LOW);
- digitalWrite(sevenseg_b, HIGH);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, LOW);
- digitalWrite(sevenseg_e, LOW);
- digitalWrite(sevenseg_f, LOW);
- digitalWrite(sevenseg_g, LOW);
- }
- } else if (r3 >= row_threshold) {
- if (c1 > column_threshold) {
- digit = '7';
- digitalWrite(sevenseg_a, LOW);
- digitalWrite(sevenseg_b, LOW);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, HIGH);
- digitalWrite(sevenseg_e, HIGH);
- digitalWrite(sevenseg_f, HIGH);
- digitalWrite(sevenseg_g, HIGH);
- } else if (c2 > column_threshold) {
- digit = '8';
- digitalWrite(sevenseg_a, LOW);
- digitalWrite(sevenseg_b, LOW);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, LOW);
- digitalWrite(sevenseg_e, LOW);
- digitalWrite(sevenseg_f, LOW);
- digitalWrite(sevenseg_g, LOW);
- } else if (c3 > column_threshold) {
- digit = '9';
- digitalWrite(sevenseg_a, LOW);
- digitalWrite(sevenseg_b, LOW);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, LOW);
- digitalWrite(sevenseg_e, HIGH);
- digitalWrite(sevenseg_f, LOW);
- digitalWrite(sevenseg_g, LOW);
- }
- } else if (r4 >= row_threshold) {
- if (c1 > column_threshold) {
- digit = '*';
- digitalWrite(sevenseg_a, HIGH);
- digitalWrite(sevenseg_b, HIGH);
- digitalWrite(sevenseg_c, HIGH);
- digitalWrite(sevenseg_d, HIGH);
- digitalWrite(sevenseg_e, HIGH);
- digitalWrite(sevenseg_f, HIGH);
- digitalWrite(sevenseg_g, LOW);
- } else if (c2 > column_threshold) {
- digit = '0';
- digitalWrite(sevenseg_a, LOW);
- digitalWrite(sevenseg_b, LOW);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, LOW);
- digitalWrite(sevenseg_e, LOW);
- digitalWrite(sevenseg_f, LOW);
- digitalWrite(sevenseg_g, HIGH);
- } else if (c3 > column_threshold) {
- digit = '#';
- digitalWrite(sevenseg_a, HIGH);
- digitalWrite(sevenseg_b, LOW);
- digitalWrite(sevenseg_c, LOW);
- digitalWrite(sevenseg_d, HIGH);
- digitalWrite(sevenseg_e, LOW);
- digitalWrite(sevenseg_f, LOW);
- digitalWrite(sevenseg_g, LOW);
- }
- }
-
-
- if (digit > 0) {
- Serial.print(" --> Key: ");
- Serial.print(digit);
- }
- Serial.println();
-
-
-
-
-
-
-
-
-
- delay(25);
- }
-
|