// SAMM CODE #include #include #include #include #include #include #include #include SdFat memory; // // Audio Setup #include SamdAudio AudioPlayer; #define NUM_AUDIO_CHANNELS 2 //could be 1,2 or 4 for sound #define AUDIO_BUFFER_SIZE 512 //512 works fine for 22.05kh, //set buffer size to 1024 for 32khz and 44.1khz for Adafruit M0 with QUAD Flash //indicate sample rate here (use audacity to convert your wav) const unsigned int sampleRate = 22050; //hz // SAMM Response wav files - noise.wav is TransTemporal Phase Cancellation product const char *filename0 = "just1mom.wav"; const char *filename1 = "moment.wav"; const char *filename2 = "fault.wav"; const char *filename3 = "function.wav"; const char *filename4 = "operatio.wav"; const char *filename5 = "sorry.wav"; const char *filename6 = "noise.wav"; // SD chip select pin (with ethernet shield : 4) #define YOUR_SD_CS 7 // // SAMM Logo const unsigned char SAMMlogo [] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x3F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xFF, 0xFE, 0x3F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0xFF, 0xFE, 0x1F, 0xFF, 0xE1, 0xC0, 0x00, 0x00, 0x00, 0x26, 0x00, 0x03, 0xEC, 0x00, 0x09, 0x72, 0xFF, 0xFF, 0x1F, 0xFF, 0xE1, 0xC0, 0x00, 0x00, 0x00, 0x60, 0x00, 0x03, 0x00, 0x00, 0x19, 0x4A, 0xFF, 0xFF, 0x1F, 0xFF, 0xE3, 0x63, 0xC7, 0x99, 0x9E, 0xF6, 0x78, 0xF3, 0x0D, 0xE7, 0xBD, 0x72, 0x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0xCF, 0xFF, 0xFF, 0xF0, 0xE1, 0xF0, 0x73, 0x80, 0xEE, 0x38, 0xE3, 0x9C, 0x71, 0xC7, 0x38, 0x00, 0xBF, 0xFF, 0xFF, 0xF0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x78, 0x73, 0x93, 0x90, 0x7F, 0x8C, 0x08, 0x10, 0x27, 0x27, 0x38, 0xC0, 0x9C, 0x39, 0xCF, 0xE7, 0x33, 0x33, 0x91, 0x93, 0x3F, 0x8F, 0x3E, 0x73, 0xE3, 0x27, 0x38, 0xF3, 0x99, 0x98, 0xCF, 0xE7, 0xE7, 0x93, 0x91, 0x93, 0x9F, 0x27, 0x3E, 0x73, 0xE3, 0x27, 0x32, 0x73, 0x93, 0xC8, 0xCF, 0xE1, 0xE7, 0x93, 0x90, 0x93, 0x9F, 0x27, 0x3E, 0x73, 0xE1, 0x27, 0x32, 0x73, 0x93, 0xC8, 0x4F, 0xF0, 0x67, 0x93, 0x92, 0x93, 0x9F, 0x27, 0x3E, 0x70, 0x25, 0x27, 0x32, 0x73, 0x93, 0xC9, 0x4F, 0xFC, 0x27, 0x93, 0x92, 0x13, 0x9F, 0x27, 0x3E, 0x73, 0xE4, 0x27, 0x32, 0x73, 0x93, 0xC9, 0x0F, 0xFF, 0x27, 0x93, 0x93, 0x13, 0x9E, 0x03, 0x3E, 0x73, 0xE6, 0x27, 0x20, 0x33, 0x93, 0xC9, 0x8F, 0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0x98, 0x9C, 0xCC, 0x9F, 0x22, 0x4F, 0x98, 0xE7, 0x9B, 0x27, 0x33, 0x9E, 0x13, 0x9E, 0x6C, 0x9C, 0x9C, 0x9C, 0xE1, 0x81, 0x36, 0x40, 0x9C, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x1C, 0x44, 0x61, 0xC4, 0x3E, 0x00, 0x00, 0x60, 0x81, 0x03, 0x08, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x64, 0x92, 0x24, 0x20, 0x00, 0x00, 0x91, 0x83, 0x04, 0x98, 0x00, 0x00, 0x00, 0x00, 0x10, 0x22, 0x64, 0x82, 0x24, 0x20, 0x04, 0x40, 0x92, 0x81, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x10, 0x22, 0x54, 0x62, 0x24, 0x3E, 0x02, 0x80, 0x94, 0x81, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x10, 0x22, 0x4C, 0x12, 0x24, 0x20, 0x02, 0x80, 0x97, 0xC1, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x4C, 0x92, 0x24, 0x20, 0x02, 0x80, 0x90, 0x81, 0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x1C, 0x44, 0x61, 0xC7, 0xBE, 0x01, 0x10, 0xE0, 0x91, 0x17, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // ************* HAL Logo *********************** const unsigned char HALlogo [] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,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 0x3B, 0x40, 0x11, 0x42, 0x05, 0x88, 0x00, 0x00, 0x5D, 0x50, 0x00, 0x00, 0x2A, 0x80, 0x00, 0x00, 0x1A, 0xAA, 0x00, 0x00, 0x2A, 0x00, 0x00, 0x00, 0x0F, 0x6D, 0x00, 0x01, 0xAD, 0x20, 0x00, 0x00, 0x05, 0x92, 0xA0, 0x16, 0x58, 0x80, 0x00, 0x00, 0x03, 0xE9, 0x6F, 0xEB, 0x60, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x30, 0x55, 0x24, 0x00, 0x00, 0x00, 0x00, 0x55, 0x97, 0x6A, 0x90, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x54, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x52, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // The Button int sammButton = 6; // audio sample window method const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz) unsigned int sample; // Microphone input variables // Microphone pin analog 1 int micLevel = 0; // SAMM Meter unsigned long sammMeter = 0; // SAMM THreshold is the Aggregate 0-100 Normalized MIC Level ADDED PER CYCLE UNTIL Threshold is MET -Threshold = 100% SAMMETER unsigned long sammThreshold = 50000; int sammFill = 0; // Status Variables const char* sammStatus[] = {"Optimized", "Sub-optimal", "PURGE MATRIX!", "Push Button!" }; // char status1[14] = "Optimized"; // char status2[14] = "Sub-Optimal"; // char status3[14] = "Purge Matrix"; //OLED Variable Setup #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // ********************************************** // *** SETUP *** // ********************************************** void setup() { // put your setup code here, to run once: Wire.begin(); Serial.begin(115200); analogReadResolution(10); //MicLevel Bit Depth analogWriteResolution(10); //Output Bit Depth // button Listen - LOW is pressed pinMode(sammButton,INPUT_PULLUP); // SD io pinmode pinMode(YOUR_SD_CS, OUTPUT); delay(100); // OLED Initialization display.begin(SSD1306_SWITCHCAPVCC, 0x3C); delay(2000); display.setTextColor(WHITE); display.clearDisplay(); //for Clearing the display display.display(); /// ****HAL Logo**** Boot display display.drawBitmap(0, 0, HALlogo, 64, 64, WHITE); // display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color) display.display(); delay(250); display.setTextSize(1); display.setCursor(68,3); display.print("HAL BIOS"); display.display(); delay(750); display.setCursor(68,15); display.print("HEURISTIC"); display.display(); delay(750); display.setCursor(68,25); display.print("ALGORITHM"); display.display(); delay(750); display.setCursor(74,35); display.print("LINK"); display.display(); delay(1750); display.setCursor(74,45); display.print("VERSION"); display.display(); delay(250); display.setCursor(68,55); display.print("V. 8999.91a"); display.display(); delay(3500); display.clearDisplay(); //for Clearing the display display.display(); // Audio Test if ( !memory.begin(YOUR_SD_CS) ) { //the sd card error was found, exit this function and to not attempt to finish Serial.println("can't start card"); } // Serial.begin(115200); // while (!Serial); // open the serial to start! Serial.print("Initializing Audio Player..."); if (AudioPlayer.begin(sampleRate, NUM_AUDIO_CHANNELS, AUDIO_BUFFER_SIZE) == -1) { Serial.println(" failed!"); return; } Serial.println(" done."); AudioPlayer.play(filename0, 1); //play 1st file on channel 1 /// ****SAMM Logo**** Boot display display.drawBitmap(0, 0, SAMMlogo, 128, 64, WHITE); // display.drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color) display.display(); delay(6000); display.clearDisplay(); display.display(); // ****************** Functional Screen **************** // *************************************************** display.clearDisplay(); display.display(); display.drawRect (0, 0, 128, 64, WHITE); // ****** Heading ******** display.setCursor(5, 3); display.print("S.A.M.M. CONSOLE(TM)"); display.drawLine(0,12,128,12,WHITE); // display STARUP display.setTextSize(2); display.setCursor(5,15); display.print("SAMM START"); display.display(); delay(1000); // ALL SYSTEMS ARE FUNCTIONAL AudioPlayer.play(filename3, 0); //play FUNCTION file on channel 0 display.setTextSize(1); display.setCursor(5,32); display.print("* All systems are *"); display.display(); delay(750); display.setCursor(5,42); display.print("**** FUNCTIONAL.****"); display.display(); delay(1500); display.setCursor(5,52); display.print("Loading Console View."); display.display(); delay(3000); display.clearDisplay(); display.display(); delay(1000); } //Purge Function void Purge (){ display.clearDisplay(); AudioPlayer.play(filename1, 0); //play MOMENT file on channel 0 // Border display.drawRect (0, 0, 128, 64, WHITE); // ****** Heading ******** display.setCursor(5, 3); display.print("S.A.M.M. CONSOLE(TM)"); display.drawLine(0,12,128,12,WHITE); // display Purge! display.setTextSize(2); display.setCursor(5,15); display.print("PURGE SAM"); display.display(); delay(1000); display.setTextSize(1); display.setCursor(5,32); display.print("Initializing routine"); display.display(); delay(1000); AudioPlayer.play(filename6, 0); //play MOMENT file on channel 0 display.setCursor(5,42); display.print("Purging local matrix"); display.display(); delay(1500); display.setCursor(5,52); display.print("*Local Matrix Clear*"); display.display(); delay(3000); display.clearDisplay(); // Border display.drawRect (0, 0, 128, 64, WHITE); // ****** Heading ******** display.setCursor(5, 3); display.print("S.A.M.M. CONSOLE(TM)"); display.drawLine(0,12,128,12,WHITE); // display Purge! display.setTextSize(2); display.setCursor(5,15); display.print("Remote SAM"); display.display(); delay(1000); display.setTextSize(1); display.setCursor(5,32); display.print("Remote Matrix Purge."); display.display(); delay(1500); display.setCursor(5,42); display.print("Purge Status: DONE!"); display.display(); delay(750); display.setCursor(5,52); display.print("S.A.M. Status: CLEAR"); display.display(); delay(1500); sammMeter = 0; // Reset Base Samm percent value. display.clearDisplay(); delay(500); AudioPlayer.play(filename4, 1); //play OPARATIONAL file on channel 1 } // ******** Pushbutton routine ************** void PushButton(){ display.clearDisplay(); AudioPlayer.play(filename2, 0); //play FAULT file on channel 0 // Border display.drawRect (0, 0, 128, 64, WHITE); // ****** Heading ******** display.setCursor(5, 3); display.print("S.A.M.M. CONSOLE(TM)"); display.drawLine(0,12,128,12,WHITE); display.display(); delay(1000); // display Warning! display.setTextSize(2); display.setCursor(5,15); display.print(" WARNING!"); // flash inver screen display.invertDisplay(true); display.display(); delay(100); display.invertDisplay(false); display.display(); delay(100); display.invertDisplay(true); display.display(); delay(100); display.invertDisplay(false); display.display(); delay(100); display.invertDisplay(true); display.display(); delay(100); display.invertDisplay(false); display.display(); delay(100); display.setTextSize(1); display.setCursor(5,32); display.print(" PURGE the SOUND"); display.setCursor(7,42); display.print("ATTENUATION MATRIX!"); display.setCursor(5,52); display.print(" PRESS BUTTON"); display.display(); // delay(10000); // display.clearDisplay(); while (digitalRead(sammButton) == HIGH) { display.invertDisplay(true); display.display(); } display.invertDisplay(false); display.display(); Purge(); } // ************************************************* // **************** LOOP ***************** // ************************************************* void loop() { // put your main code here, to run repeatedly: // Sorry Dave (If less than 50% Full) if (digitalRead(sammButton) == LOW) { if (sammFill <= 5) { // ****************** I'm Sorry Dave Screen **************** // *************************************************** display.clearDisplay(); display.display(); display.drawRect (0, 0, 128, 64, WHITE); // ****** Heading ******** display.setCursor(5, 3); display.print("S.A.M.M. CONSOLE(TM)"); display.drawLine(0,12,128,12,WHITE); // display STARUP display.setTextSize(2); display.setCursor(5,15); display.print("**ERROR!**"); display.display(); delay(250); // ALL SYSTEMS ARE FUNCTIONAL AudioPlayer.play(filename5, 0); //play SORRY file on channel 0 display.setTextSize(1); display.setCursor(5,32); display.print(" I'm sorry, Dave..."); display.display(); delay(1500); display.setCursor(8,42); display.print("I'm afraid I can't"); display.display(); delay(900); display.setCursor(5,52); display.print("** ...do that... **"); display.display(); delay(3000); display.clearDisplay(); display.display(); } else { Purge(); } } // SAmple Window method unsigned long startMillis= millis(); // Start of sample window unsigned int peakToPeak = 0; // peak-to-peak level unsigned int signalMax = 0; unsigned int signalMin = 1024; // collect data for 50 mS while (millis() - startMillis < sampleWindow) { sample = analogRead(1); if (sample < 1024) // toss out spurious readings { if (sample > signalMax) { signalMax = sample; // save just the max levels } else if (sample < signalMin) { signalMin = sample; // save just the min levels } } } peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude // *****************Mic level ***************** micLevel = peakToPeak; // read the sample output calculation micLevel = map(micLevel, 0,1023,0,100); // Remap mic level 0-100 if (micLevel < 1) { micLevel = 0; } else if (micLevel > 100) { micLevel = 100; } // Serial.println(micLevel); // debug value // delay(50); // ************End micLevel***************** // ************ SAMM Meter **************** if (micLevel > 5) { sammMeter = sammMeter + micLevel; } // Serial.println(sammMeter); sammFill = map(sammMeter, 0,sammThreshold,0,100); if (sammFill < 1) { sammFill = 0; } else if (sammFill > 100) { sammFill = 100; } Serial.println(sammFill); // ***********StatusValues************ //**************** Console Display********************** display.clearDisplay(); // Border display.drawRect (0, 0, 128, 64, WHITE); // ****** Heading ******** display.setCursor(5, 3); display.print("S.A.M.M. CONSOLE(TM)"); display.drawLine(0,12,128,12,WHITE); // display Intensity Values display.setTextSize(1); display.setCursor(5,15); display.print(micLevel); display.drawRect (22, 15, 103, 8, WHITE); display.fillRect (24, 17, micLevel, 4, WHITE); display.drawLine(0,25,128,25,WHITE); // Display SmmFIll percentage display.setTextSize(1); display.setCursor(3,28); display.print(" %"); display.setCursor(3,38); display.print(sammFill); display.drawRect (22, 29, 104, 16, WHITE); display.fillRect (24, 31, sammFill, 12, WHITE); display.drawLine(0,48,128,48,WHITE); display.setTextSize(1); display.setCursor(3, 52); display.print("Status: "); if (sammFill > 99) { display.print(sammStatus[3]); PushButton(); } else if (sammFill >= 90) { display.print(sammStatus[2]); } else if (sammFill >= 80) { display.print(sammStatus[1]); } else { display.print(sammStatus[0]); } display.display(); }