You are on page 1of 5

/* "Senza" .zZ.

(oscarOctavioSozaFigueroa) "sense the environment and traduce into a scale of musical notation" MIGAA-migratingArtsAcademies Vilnius_Lithuania 2013_december Using ARDUINO UNO, Music Instrument Shield and LIGHT&TEMPERATURE sensors Creative COmmons License */

//MIDI #include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); // RX, TX byte fractal=0; //Fractal opertion between the relation with the TEMPERATURE & LIGHT byte note = 0; //The MIDI note value to be initialized byte noteT = 60; //note incresse or dicreese with the TEMPERATURE byte noteL = 0; //note for initialized LIGHT byte resetMIDI = 4; //Tied to VS1053 Reset line byte ledPin = 13; //MIDI traffic inidicator int instrumentL = 98; //instrumentLIGHT int instrumentL2= 9; //second instrumentLIGHT int instrumentT= 14; //instrumentTEMPEMPERATURE int instrumentT2= 98; //second instrumentTEMPERATURE //MIDI //light int lightPin = 5; //AnlogPIN 5 int LightNEW; //variable for read the sensor int LightOLD; //variable to compare //light //temperature C int tempPin=0; //AnalogPIN 0 int a; // read of the sensor of the temperature float ctemperature; //variable for read the sensor float ctemperatureOLD; //variable to compare int B=3975; //conversion from DC to C float resistance; //temperature C void setup() { Serial.begin(57600); //Setup MIDI control mySerial.begin(31250);

pinMode(resetMIDI, OUTPUT); digitalWrite(resetMIDI, LOW); delay(100); digitalWrite(resetMIDI, HIGH); delay(100); talkMIDI(0xB0, 0x07, 60); //Setup MIDI control } void loop() { talkMIDI(0xB0, 0, 0x79); //Bank select Melodic MIDI instruments //TEMPERATURE //(a)=representation of the temperature in musical notation a=analogRead(tempPin); resistance=(float)(1023-a)*10000/a; ctemperature=1/(log(resistance/10000)/B+1/298.15)-273.15; //notation increases when the temperature changes in the positive direction if ( ctemperature > ctemperatureOLD) { Serial.print("temp+: "); Serial.print(ctemperature); Serial.write(186); Serial.println("C "); /////////////////////////////////////// talkMIDI(0xC0, instrumentT, 0); note= noteT+1; //Note on channel 1 noteOn(0, note, 100); delay(50); //Turn off the note noteOff(0, note, 100); delay(50); Serial.println(note); noteT=note; /////////////////////////////////////// talkMIDI(0xC0, instrumentT2, 0); note=(noteT+12); //Note on channel 1 noteOn(0, note, 60); delay(50); //Turn off the note noteOff(0, note, 60); delay(50); Serial.println(note); delay(100); } else{delay(random(500,800));} //notation decreases when the temperature changes in the negative direction if ( ctemperature < ctemperatureOLD) {

Serial.print("temp-: "); Serial.print(ctemperature); Serial.write(186); Serial.println("C "); /////////////////////////////////////// talkMIDI(0xC0, instrumentT, 0); note= noteT-1; //Note on channel 1 noteOn(0, note, 100); delay(50); //Turn off the note noteOff(0, note, 100); delay(50); Serial.println(note); noteT=note; /////////////////////////////////////// talkMIDI(0xC0, instrumentT2, 0); note= noteT-12; //Note on channel 1 noteOn(0, note, 60); delay(50); //Turn off the note noteOff(0, note, 60); delay(50); Serial.println(note); delay(100); } else{delay(random(500,800));} ctemperatureOLD=ctemperature;

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<// //LIGHT //(bi)=randomical perception of the changes of the light into a musical notation LightNEW=analogRead(lightPin); if ( LightNEW != LightOLD) { Serial.print("light: "); Serial.println(LightNEW); ///////////////////////////////////////////> talkMIDI(0xC0, instrumentL, 0); note=random(90,120); //Note on channel 1 noteOn(0, note, 60); delay(50); //Turn off the note noteOff(0, note, 60); delay(50); Serial.println(note); noteL=note; ////////////////////////////////////////////>

talkMIDI(0xC0, instrumentL2, 0); note=random(120,140); //Note on channel 1 noteOn(0, note, 100); delay(50); //Turn off the note noteOff(0, note, 100); delay(50); Serial.println(note); delay(100); } else {delay(random(500,800));} LightOLD=LightNEW; //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<// /* FRACTAL operation between the two sensors according with the formula: Z=(a+bi)*2 + C Z=fractal operation a=temperature with the system of musical notation bi=light with the randomical representation with notes C= randomic scale of musical notation */ fractal=(noteT+noteL)*2+(random(13)); Serial.print(">>>fractal: "); Serial.println(fractal); talkMIDI(0xC0, 90, 0); note=fractal; //Note on channel 1 noteOn(0, note, 200); delay(50); //Turn off the note noteOff(0, note, 200); delay(50); Serial.println(note); } //Send a MID note-on message. void noteOn(byte channel, byte note, byte attack_velocity) { talkMIDI( (0x90 | channel), note, attack_velocity); } //Send a MIDI note-off message. void noteOff(byte channel, byte note, byte release_velocity) { talkMIDI( (0x80 | channel), note, release_velocity); } //Plays a MIDI note. void talkMIDI(byte cmd, byte data1, byte data2) { digitalWrite(ledPin, HIGH); mySerial.write(cmd); mySerial.write(data1);

//Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes if( (cmd & 0xF0) <= 0xB0) mySerial.write(data2); digitalWrite(ledPin, LOW); }

You might also like