Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- midi leds
- pier giuliano nioi
- http://piergiu.wordpress.com
- */
- union serial_super_data {
- unsigned long int_4_bytes;
- unsigned char read_byte[4];
- } super_data;
- //setup: declaring inputs and outputs and begin serial
- void setup() {
- pinMode(2,OUTPUT);
- pinMode(3,OUTPUT);
- pinMode(4,OUTPUT);
- pinMode(5,OUTPUT);
- pinMode(6,OUTPUT);
- Serial.begin(57600);
- }
- //loop: wait for serial data, and interpret the message
- void loop () {
- if (Serial.available() >= 3) // wait for three bytes
- {
- for(int i=0;i <=3; i++)
- super_data.read_byte[i]=Serial.read();
- switch (super_data.read_byte[0]) {
- case 144:// note on message starting starting
- lightLed(super_data.read_byte[1], HIGH);
- break;
- case 128:// note off message starting
- lightLed(super_data.read_byte[1], LOW);
- break;
- default:
- break;//nada
- }//end switch
- }//end if
- }//end loop
- void lightLed(byte note, int value){
- if(note>=65 && note<=69){
- digitalWrite(note-63, value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement