// Gakken SX-150 Midi control // Hector Urtubia - urtubia@mrbook.org // More info @ http://mrbook.org #define DATAOUT 11//MOSI #define DATAIN 12//MISO - not used, but part of builtin SPI #define SPICLOCK 13//sck #define SLAVESELECT 10//ss int ledPin = 3; // LED connected to digital pin 3 int action=2; //0 =note off ; 1=note on ; 2= nada byte incomingByte; byte note; byte velocity; int notesPushed = 0; void setup() // run once, when the sketch starts { //pinMode(ledPin, OUTPUT); // sets the digital pin as output // Control Voltage Section byte clr; pinMode(DATAOUT, OUTPUT); pinMode(DATAIN, INPUT); pinMode(SPICLOCK,OUTPUT); pinMode(SLAVESELECT,OUTPUT); digitalWrite(SLAVESELECT,HIGH); //disable device SPCR = (1<> 8) & 0x00FF; dacSPI0 |= 0x10; dacSPI1 = sample & 0x00FF; digitalWrite(SLAVESELECT,LOW); SPDR = dacSPI0; // Start the transmission while (!(SPSR & (1<0){ value=HIGH; }else{ value=LOW; } //digitalWrite(ledPin, value); if(value==HIGH){ notesPushed++; playNote(note); analogWrite(ledPin, 255); }else{ notesPushed--; if(notesPushed < 0) notesPushed = 0; if(notesPushed == 0){ noteOff(); analogWrite(ledPin, 0); } } } int potValue; void loop() { /* potValue = (int)( ((1023 - analogRead(0)) / 1023.0) * 255); analogWrite(ledPin, potValue); */ while (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read(); // wait for as status-byte, channel 1, note on or off if (incomingByte== 144){ // note on message starting starting action=1; } else if (incomingByte== 128){ // note off message starting action=0; }else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte) note=incomingByte; playMidiNote(note, 0); note=0; velocity=0; action=2; } else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte) note=incomingByte; }else if ( (action==1)&&(note!=0) ){ // ...and then the velocity velocity=incomingByte; playMidiNote(note, velocity); note=0; velocity=0; action=2; } } } void blink() { digitalWrite(ledPin, HIGH); delay(30); digitalWrite(ledPin, LOW); delay(30); digitalWrite(ledPin, HIGH); delay(30); digitalWrite(ledPin, LOW); delay(30); }