This shows you the differences between two versions of the page.
|
pm:prj2023:apredescu:sintetizator [2023/05/28 22:57] radu_andrei.popescu [Software Design] |
pm:prj2023:apredescu:sintetizator [2023/05/28 23:36] (current) radu_andrei.popescu |
||
|---|---|---|---|
| Line 57: | Line 57: | ||
| **Implementare** | **Implementare** | ||
| * Pentru citirea input-ului MIDI: | * Pentru citirea input-ului MIDI: | ||
| - | ''void MIDI_poll(); | + | <code> |
| + | ... | ||
| + | void MIDI_poll(); | ||
| void setup() | void setup() | ||
| Line 86: | Line 88: | ||
| do { | do { | ||
| if ( (size = Midi.RecvData(outBuf)) > 0 ) { | if ( (size = Midi.RecvData(outBuf)) > 0 ) { | ||
| - | if (outBuf[0] == 144) { | + | if (outBuf[0] == 144) { // 144 reprezintă codul pentru când se apasă clapa respectivă |
| _MIDI_SERIAL_PORT.print(outBuf[1], DEC); | _MIDI_SERIAL_PORT.print(outBuf[1], DEC); | ||
| _MIDI_SERIAL_PORT.println(); | _MIDI_SERIAL_PORT.println(); | ||
| Line 93: | Line 95: | ||
| } while (size > 0); | } while (size > 0); | ||
| } | } | ||
| - | '' | + | ... |
| + | </code> | ||
| + | |||
| + | * Pentru citirea input-ului de pe cealaltă placă Arduino: | ||
| + | <code> | ||
| + | ... | ||
| + | if (Serial.available() > 0) { | ||
| + | // Read the incoming data | ||
| + | c = Serial.read(); | ||
| + | if (c != '\n'){ | ||
| + | note[i++] = c; | ||
| + | } else { | ||
| + | note[i] = c; | ||
| + | i = 0; | ||
| + | note_int = atoi(note); | ||
| + | Serial.print(note_int); | ||
| + | } | ||
| + | ... | ||
| + | </code> | ||
| + | |||
| + | * Pentru a cânta nota primită ca input: | ||
| + | <code> | ||
| + | ... | ||
| + | if (note_int != 0){ | ||
| + | sprintf(file, "%s%d.wav", MIDI_to_note(note_int), curr_preset); | ||
| + | Serial.print(file); | ||
| + | Serial.println(); | ||
| + | tmrpcm.play(file); | ||
| + | } | ||
| + | ... | ||
| + | </code> | ||
| + | |||
| + | * Pentru a citi valoarea potențiometrului și pentru a afișa preset-ul ales: | ||
| + | <code> | ||
| + | ... | ||
| + | void loop() { | ||
| + | val = analogRead(A0); | ||
| + | val = map(val, 0, 1020, 1, 6); | ||
| + | |||
| + | if (val != curr_preset && val != 6){ | ||
| + | curr_preset = val; | ||
| + | printPreset(); | ||
| + | } | ||
| + | } | ||
| + | ... | ||
| + | void printPreset(){ | ||
| + | clearCharacters(); | ||
| + | lcd.setCursor(0,1); | ||
| + | if (curr_preset == 5) | ||
| + | lcd.print("Drums"); | ||
| + | else lcd.print(curr_preset); | ||
| + | } | ||
| + | ... | ||
| + | void clearCharacters() | ||
| + | { | ||
| + | for (int i = 0; i < 10; i++) | ||
| + | { | ||
| + | lcd.setCursor (i,1); // | ||
| + | lcd.write(254); | ||
| + | } | ||
| + | |||
| + | } | ||
| + | ... | ||
| + | </code> | ||
| + | |||
| + | De asemenea, pentru a converti valoarea input-ului MIDI într-o notă muzicală, am creat propria bibliotecă. | ||
| + | **input_converter.cpp:** | ||
| + | <code> | ||
| + | #include "input_converter.h" | ||
| + | |||
| + | char* MIDI_to_note(int note) { | ||
| + | if (note == 60) | ||
| + | return "C1"; | ||
| + | if (note == 61) | ||
| + | return "C#1"; | ||
| + | if (note == 62) | ||
| + | return "D1"; | ||
| + | if (note == 63) | ||
| + | return "D#1"; | ||
| + | if (note == 64) | ||
| + | return "E1"; | ||
| + | if (note == 65) | ||
| + | return "F1"; | ||
| + | if (note == 66) | ||
| + | return "F#1"; | ||
| + | if (note == 67) | ||
| + | return "G1"; | ||
| + | if (note == 68) | ||
| + | return "G#1"; | ||
| + | if (note == 69) | ||
| + | return "A1"; | ||
| + | if (note == 70) | ||
| + | return "A#1"; | ||
| + | if (note == 71) | ||
| + | return "B1"; | ||
| + | return ""; | ||
| + | } | ||
| + | </code> | ||
| ===== Rezultate Obţinute ===== | ===== Rezultate Obţinute ===== | ||
| Line 123: | Line 223: | ||
| <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | ||
| - | |||