Commits

Jody McAdams committed fd337f3

green flash for blank notes

Comments (0)

Files changed (1)

Experimental/MusicMachine/MusicMachine.ino

                                  { 1,1,1,0,0,1,1 }   // = 9
                                                            };
 
-const char g_numNotes = 12;                                                          
+const char g_numNotes = 13;                                                          
 byte seven_seg_notes[g_numNotes][8] = {                                 
                                  { 1,0,0,1,1,1,0,0 },  // = C
                                  { 1,0,0,1,1,1,0,1 },  // = C#
                                  { 1,1,1,0,1,1,1,0 },  // = A
                                  { 1,1,1,0,1,1,1,1 },  // = A#
                                  { 0,0,1,1,1,1,1,0 },  // = B
+                                 { 1,1,1,1,1,1,1,0 },  // = NULL
                                                            };
 
 int g_numNotesInSet = 12;
 int g_buzzerPin = 11;
 int g_buttonPin1 = 12;
 int g_buttonPin2 = 13;
-int g_ledPin = 2;
+int g_ledPin_Green = 1;
+int g_ledPin_Blue = 2;
 
 void setup() {                
   pinMode(3, OUTPUT);//Anode A
   pinMode(g_buttonPin1, INPUT);  // declare g_buttonPin1 as an INPUT
   pinMode(g_buttonPin2, INPUT);  // declare g_buttonPin2 as an INPUT
   
-  pinMode(g_ledPin, OUTPUT);  // declare g_buttonPin2 as an OUTPUT
+  pinMode(g_ledPin_Blue, OUTPUT);  // declare g_buttonPin2 as an OUTPUT
+  pinMode(g_ledPin_Green, OUTPUT);  // declare g_buttonPin2 as an OUTPUT
 }
 
 void writeDot(byte dot) {
 int g_recordBleepTime = 100;
 
 void loop() {
+  int theNullNote = (g_numNotes-1);
   
   int potVal = analogRead(g_potPin);    // read the value from the sensor
   float potFrac = 1.0f-(potVal/1023.0f);
         
         g_songFinished = false;
         g_numNotesRecorded = 0;
+        
+        //Turn off the lights
+        digitalWrite(g_ledPin_Blue, LOW);
+        digitalWrite(g_ledPin_Green, LOW);
       }
       
       
         //Display current note
         int theNote = g_recordedNotes[g_playBackIndex];
         sevenSegWriteNote(theNote);
-        tone(g_buzzerPin,g_notes[theNote+g_noteOffset],200);
-        digitalWrite(g_ledPin, HIGH);
+        if(theNote == theNullNote)
+        {
+          tone(g_buzzerPin,0,200);
+        }
+        else
+        { 
+          tone(g_buzzerPin,g_notes[theNote+g_noteOffset],200);
+        }
+        
+        digitalWrite(g_ledPin_Blue, HIGH);
+        
+        //Show green for sharp notes
+        if(theNote == theNullNote)
+         {
+           digitalWrite(g_ledPin_Green, HIGH);
+         }
+         
         delay(50);
-        digitalWrite(g_ledPin, LOW);
+        
+        digitalWrite(g_ledPin_Blue, LOW);
+        digitalWrite(g_ledPin_Green, LOW);
+        
         delay(500*(1.0f-potFrac));
         noTone(g_buzzerPin);
         
         //Test the note before recording
        if(buttonState1 == HIGH)
         {
-         tone(g_buzzerPin,g_notes[potBasedNote+g_noteOffset],100);
+          if(potBasedNote != theNullNote)
+          {
+           tone(g_buzzerPin,g_notes[potBasedNote+g_noteOffset],100);
+          }
         }
         else
          {
       //Record the note on button press
       if(g_allowRecord && (buttonState2 == HIGH))
        {
-         tone(g_buzzerPin,g_notes[potBasedNote+g_noteOffset],g_recordBleepTime);
+         if(potBasedNote == theNullNote)
+          {
+            digitalWrite(g_ledPin_Green, HIGH);
+          }
+          else
+           {
+             tone(g_buzzerPin,g_notes[potBasedNote+g_noteOffset],g_recordBleepTime);
+           }
+         
          delay(g_recordBleepTime);
          noTone(g_buzzerPin);
+         digitalWrite(g_ledPin_Green, LOW);
          
          g_recordedNotes[g_numNotesRecorded] = potBasedNote;
          ++g_numNotesRecorded;