-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from DhrBaksteen/Drums_Update
Drums Update
- Loading branch information
Showing
7 changed files
with
121 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* This is a simple demo sketch for the OPL2 library. It makes use of the Cheerful Electronic Piano Board | ||
* (https://www.tindie.com/products/cheerful/arduino-piano-board-2/) and assumes then you also have the | ||
* ArduinoPianoBoard library installed (see https://github.com/DhrBaksteen/ArduinoPianoBoard). | ||
* | ||
* This sketch makes a drum machine out of the Piano Board. The first 5 white keys are used to play various drum sounds. | ||
* | ||
* OPL2 Board is connected as follows: | ||
* Pin 8 - Reset | ||
* Pin 9 - A0 | ||
* Pin 10 - Latch | ||
* Pin 11 - Data | ||
* Pin 13 - Shift | ||
* | ||
* Piano Board is connected as follows: | ||
* Pin 7 - /SS | ||
* Pin 12 - MISO | ||
* Pin 13 - SCK | ||
* | ||
* Code by Maarten Janssen (maarten@cheerful.nl) 2020-04-11 | ||
* Most recent version of the library can be found at my GitHub: https://github.com/DhrBaksteen/ArduinoOPL2 | ||
*/ | ||
|
||
#include <SPI.h> | ||
#include <OPL2.h> | ||
#include <PianoKeys.h> | ||
#include <instruments.h> | ||
|
||
#define NO_DRUM 255 | ||
|
||
OPL2 opl2; | ||
PianoKeys piano(7); | ||
|
||
|
||
byte drums[8] = {DRUM_BASS, NO_DRUM, DRUM_SNARE, NO_DRUM, DRUM_TOM, DRUM_HI_HAT, NO_DRUM, DRUM_CYMBAL}; | ||
|
||
|
||
void setup() { | ||
opl2.init(); | ||
|
||
// Load drum instruments and set percusive mode. | ||
Instrument bass = opl2.loadInstrument(INSTRUMENT_BDRUM1); | ||
Instrument snare = opl2.loadInstrument(INSTRUMENT_RKSNARE1); | ||
Instrument tom = opl2.loadInstrument(INSTRUMENT_TOM2); | ||
Instrument cymbal = opl2.loadInstrument(INSTRUMENT_CYMBAL1); | ||
Instrument hihat = opl2.loadInstrument(INSTRUMENT_HIHAT2); | ||
|
||
opl2.setPercussion(true); | ||
opl2.setDrumInstrument(bass); | ||
opl2.setDrumInstrument(snare); | ||
opl2.setDrumInstrument(tom); | ||
opl2.setDrumInstrument(cymbal); | ||
opl2.setDrumInstrument(hihat); | ||
} | ||
|
||
|
||
void loop() { | ||
piano.updateKeys(); | ||
|
||
// Handle keys that are being pressed. | ||
for (int i = KEY_C; i <= KEY_G; i ++) { | ||
if (piano.wasKeyPressed(i) && drums[i] != NO_DRUM) { | ||
opl2.playDrum(drums[i], 4, NOTE_C); | ||
} | ||
} | ||
|
||
delay(20); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters