Commits

Jody McAdams committed 9fe1d9d

it is now cycling through the notes while playing/displaying them

Comments (0)

Files changed (1)

Experimental/MusicMachine/MusicMachine.ino

+// Arduino 7 segment display example software
+// http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html
+// License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
+/* 
+Pins starts from top left
+
+1. Anode F          LED Pin 1        Arduino Pin 8
+2. Anode G          LED Pin 2        Arduino Pin 9
+3. No Pin
+4. Common Cathode
+5. No Pin
+6. Anode E          LED Pin 6        Arduino Pin 7
+7. Anode D          LED Pin 7        Arduino Pin 6
+8. Anode C          LED Pin 8        Arduino Pin 5
+9. Anode RHDP       LED Pin 9        Arduino Pin 10
+10. No Pin
+11. No Pin
+12. Common Cathode  
+13. Anode B         LED Pin 13       Arduino Pin 4
+14. Anode A         LED Pin 14       Arduino Pin 3
+*/
+
+// Define the LED digit patters, from 0 - 9
+// Note that these patterns are for common cathode displays
+// For common anode displays, change the 1's to 0's and 0's to 1's
+// 1 = LED on, 0 = LED off, in this order:
+//                                    Arduino pin: 3,4,5,6,7,8,9,
+
+const char g_numDigits = 10;
+byte seven_seg_digits[g_numDigits][7] = {
+                                 { 1,1,1,1,1,1,0 },  // = 0
+                                 { 0,1,1,0,0,0,0 },  // = 1
+                                 { 1,1,0,1,1,0,1 },  // = 2
+                                 { 1,1,1,1,0,0,1 },  // = 3
+                                 { 0,1,1,0,0,1,1 },  // = 4
+                                 { 1,0,1,1,0,1,1 },  // = 5
+                                 { 1,0,1,1,1,1,1 },  // = 6
+                                 { 1,1,1,0,0,0,0 },  // = 7
+                                 { 1,1,1,1,1,1,1 },  // = 8
+                                 { 1,1,1,0,0,1,1 }   // = 9
+                                                           };
+
+const char g_numNotes = 12;                                                          
+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#
+                                 { 0,1,1,1,1,0,1,0 },  // = D
+                                 { 0,1,1,1,1,0,1,1 },  // = D#
+                                 { 1,0,0,1,1,1,1,0 },  // = E
+                                 { 1,0,0,0,1,1,1,0 },  // = F
+                                 { 1,0,0,0,1,1,1,1 },  // = F#
+                                 { 1,1,1,1,0,1,1,0 },  // = G
+                                 { 1,1,1,1,0,1,1,1 },  // = G#
+                                 { 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
+                                                           };
+
+int g_numNotesInSet = 12;                             
+int g_notes[] =
+{
+  
+//1
+33,
+35,
+37,
+39,
+41,
+44,
+46,
+49,
+52,
+55,
+58,
+62,
+
+//2
+65,
+69,
+73,
+78,
+82,
+87,
+93,
+98,
+104,
+110,
+117,
+123,
+
+//3
+131,
+139,
+147,
+156,
+165,
+175,
+185,
+196,
+208,
+220,
+233,
+247,
+
+//4
+262,
+277,
+294,
+311,
+330,
+349,
+370,
+392,
+415,
+440,
+466,
+494,
+
+//5
+523,
+554,
+587,
+622,
+659,
+698,
+740,
+784,
+831,
+880,
+932,
+988,
+
+//6
+1047,
+1109,
+1175,
+1245,
+1319,
+1397,
+1480,
+1568,
+1661,
+1760,
+1865,
+1976,
+
+//7
+2093,
+2217,
+2349,
+2489,
+2637,
+2794,
+2960,
+3136,
+3322, 
+3520,
+3729,
+3951,
+
+};
+                          
+int g_numNotesRecorded = 0;
+
+const int g_numRecordableNotes = 3;
+int g_recordedNotes[g_numRecordableNotes];
+
+void setup() {                
+  pinMode(3, OUTPUT);//Anode A
+  pinMode(4, OUTPUT);//Anode B  
+  pinMode(5, OUTPUT);//Anode C
+  pinMode(6, OUTPUT);//Anode D
+  pinMode(7, OUTPUT);//Anode E
+  pinMode(8, OUTPUT);//Anode F
+  pinMode(9, OUTPUT);//Anode G
+  pinMode(10, OUTPUT);//Anode RHDP (right hand decimal place)
+  
+  writeDot(0);  // start with the "dot" off
+}
+
+void writeDot(byte dot) {
+  digitalWrite(10, dot);
+}
+    
+void sevenSegWriteDigit(byte digit) {
+  byte pin = 3;
+  for (byte segCount = 0; segCount < 7; ++segCount) {
+    digitalWrite(pin, seven_seg_digits[digit][segCount]);
+    ++pin;
+  }
+}
+
+void sevenSegWriteNote(byte noteIndex) {
+  byte pin = 3;
+  for (byte segCount = 0; segCount < 8; ++segCount) {
+    digitalWrite(pin, seven_seg_notes[noteIndex][segCount]);
+    ++pin;
+  }
+}
+
+void loop() {
+  for (byte count = 0; count < g_numNotes; ++count) {
+   delay(500);
+   sevenSegWriteNote(count); 
+   tone(11,g_notes[count+g_numNotesInSet*3],1000);
+  }
+  
+  //delay(2000);
+}