Last active
December 30, 2018 07:13
-
-
Save tadfmac/20df8ec29d7f66bb61758983a997ae44 to your computer and use it in GitHub Desktop.
Arduboy を MIDIConにしたやつ。
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
// Dependencies: | |
// https://github.com/MLXXXp/Arduboy2 | |
// https://github.com/MLXXXp/ArduboyTones | |
// https://github.com/arduino-libraries/MIDIUSB | |
// For Testing | |
// https://mz4u.net/cans-simulator/ | |
#include "Arduboy2.h" | |
#include <ArduboyTones.h> | |
#include "MIDIUSB.h" | |
Arduboy2 arduboy; | |
ArduboyTones sound(arduboy.audio.enabled); | |
char text[] = "MIDI Con!!"; | |
byte x; | |
byte y; | |
#define CHAR_WIDTH 6 | |
#define CHAR_HEIGHT 8 | |
#define NUM_CHARS (sizeof(text) - 1) | |
midiEventPacket_t midievent; | |
void setup() { | |
arduboy.begin(); | |
arduboy.setFrameRate(30); | |
arduboy.audio.on(); | |
midievent.header = 0x09; | |
midievent.byte1 = 0x90; | |
midievent.byte3 = 120; | |
x = (WIDTH / 2) - (NUM_CHARS * CHAR_WIDTH / 2); | |
y = (HEIGHT / 2) - (CHAR_HEIGHT / 2); | |
} | |
#define BUTTONS_NUM 6 | |
uint8_t oButton = 0; | |
uint8_t notes[] = {36,38,40,43,45,48}; | |
void loop() { | |
uint8_t button; | |
uint8_t cnt; | |
button = 0; | |
if(arduboy.pressed(UP_BUTTON)){ | |
button |= 0x01; | |
} | |
if(arduboy.pressed(LEFT_BUTTON)) { | |
button |= 0x02; | |
} | |
if(arduboy.pressed(DOWN_BUTTON)){ | |
button |= 0x04; | |
} | |
if(arduboy.pressed(RIGHT_BUTTON)) { | |
button |= 0x08; | |
} | |
if(arduboy.pressed(A_BUTTON)) { | |
button |= 0x10; | |
} | |
if(arduboy.pressed(B_BUTTON)) { | |
button |= 0x20; | |
} | |
for(cnt = 0;cnt < BUTTONS_NUM;cnt ++){ | |
if((button & (1 << cnt)) != 0){ | |
if((oButton & (1 << cnt)) == 0){ | |
midievent.byte2 = notes[cnt]; // MIDI Note Number : 20-25 | |
MidiUSB.sendMIDI(midievent); | |
MidiUSB.flush(); | |
sound.tone(300+300*cnt, 30); | |
} | |
} | |
} | |
oButton = button; | |
if (!(arduboy.nextFrame())){ | |
return; | |
} | |
arduboy.clear(); | |
arduboy.setCursor(x, y); | |
arduboy.print(text); | |
arduboy.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment