Lighting musical keys [Example 1]
i'm working on musical instrument turn on led based on key in struck. 16 keys on on multiplexer , 16 led on on port expander.
based on 2 project in arduino playground.
i'm trying add statements
noteon = ledon
noteoff =ledoff
midi_footsteps exact example i'm trying accomplish
this how mike did http://www.thebox.myzen.co.uk/hardware/midi_footsteps_files/footsteps%20software.zip it's homepage http://www.thebox.myzen.co.uk/hardware/midi_footsteps.html
can implement port expander , led's section of project sketch attached.
the musical instrument part of mod based on yaami-drum found here http://sourceforge.net/projects/yaamidrum/
based on 2 project in arduino playground.
i'm trying add statements
noteon = ledon
noteoff =ledoff
midi_footsteps exact example i'm trying accomplish
this how mike did http://www.thebox.myzen.co.uk/hardware/midi_footsteps_files/footsteps%20software.zip it's homepage http://www.thebox.myzen.co.uk/hardware/midi_footsteps.html
can implement port expander , led's section of project sketch attached.
the musical instrument part of mod based on yaami-drum found here http://sourceforge.net/projects/yaamidrum/
below parts i've identified has i2c expander , led. constructing statement , placing @ right point in program still little sketchy.
code: [select]
// defines
// i2c registers
#define i2cregisterinput 0
#define i2cregisteroutput 2
#define i2cregisterpolarity 4
#define i2cregisterconfig 6
#define i2cregisterinterrupt 8
#define i2cregisterexpander 10
// i2c device addresses
#define ledaddress (0x20 | 0x0) // address of trigger led indicators output
// control switch device bit masks
#define ddrtrigger 0x00000 // data direction register trigger indictor leds
int lastledval;
#include <wire.h>
lastledval = 0; //leds off
// setup i2c devices
wire.begin(); // start i2c interface
// initilise registers
gpio_write(ledaddress, ddrtrigger, i2cregisterconfig); // make outputs
gpio_write(ledaddress, 0, i2cregisterinput); // turn them off
int ledval = 0;
int ledmask = 1;
for(int i=0; i<16; i++){
if(currentstate[i] < threshold) ledval |= ledmask; // add 1 in position of sensors under threshold
ledmask = ledmask << 1; // less on leds off
}
if(lastledval != ledval) { // has changed
ledmask = 1; // led on
for(int i=0; i<16; i++){
if((ledmask & ledval) != (ledmask & lastledval)){
if((ledmask & ledval) == 0) {
// note off
controlsend(0x80, control[i], 0x00); // turn off control message
//notone(8);
digitalwrite(ledpin,low);
}
else{
// note on
controlsend(0x90, control[i], currentstate[i]>>3); // turn on control message
//tone(8, notes[i], 20);
digitalwrite (ledpin,high);
}
}
ledmask = ledmask << 1; // led high
}
// update trigger leds
gpio_writebyteinverse(ledaddress, ledval, i2cregisterinput); // update leds
}
lastledval = ledval; // record current state of leds , midi notes / messages
digitalwrite(ledpin,low);
}
void gpio_write(int address, int data, int reg) {
// send output register address
wire.begintransmission(address);
wire.send(reg);
// connect device , send 2 bytes
wire.send(0xff & data); // low byte
wire.send(data >> 8); // high byte
wire.endtransmission();
}
void gpio_writebyteinverse(int address, int data, int reg) {
// send output register address
wire.begintransmission(address);
wire.send(reg);
// connect device , send 2 bytes
wire.send(data >> 8); // high byte
wire.send(0xff & data); // low byte
wire.endtransmission();
}
int gpio_read(int address) {
int data = 0;
// send input register address
wire.begintransmission(address);
wire.send(i2cregisterinput);
wire.endtransmission();
// connect device , request 2 bytes
// wire.begintransmission(address);
wire.requestfrom(address, 2);
if (!wire.available()) { } // nothing until data arrives
data = wire.receive();
if (!wire.available()) { } // nothing until data arrives
data |= wire.receive() << 8;
wire.endtransmission();
return data;
}
Arduino Forum > Using Arduino > Audio > Lighting musical keys [Example 1]
arduino
Comments
Post a Comment