Synthesizer / Mbed 2 deprecated DBSMUSICPROJ

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.hpp Source File

main.hpp

00001 #ifndef __main__
00002 #define __main__
00003 #include "variables.hpp"
00004 #include "math.hpp"
00005 InterruptIn clockin(PB_0);
00006 DigitalIn runsw(PC_0);
00007 DigitalIn loopsw(PC_1);
00008 AnalogIn analog_valuea(PA_0);
00009 AnalogIn analog_valueb(PA_4);
00010 AnalogIn analog_valuec(PB_2);
00011 DigitalOut led(PC_2);
00012 BusOut multiplexa(PC_4,PC_5,PC_6);
00013 BusOut multiplexb(PC_7,PC_8,PC_9);
00014 BusOut multiplexc(PC_10,PC_11,PC_12);
00015 DigitalOut ledclock(PB_10);
00016 DigitalOut ledlatch(PB_12);
00017 DigitalOut leddata(PB_11);
00018 DigitalOut lrun(PC_2);
00019 DigitalOut lloop(PC_3);
00020 DigitalOut trigout(PA_5);
00021 SPI dac(PB_5,PB_4,PB_3);
00022 Serial pc(PB_6, PA_10);
00023 DigitalOut cs(PB_9);
00024 DigitalOut clockout(PA_12);
00025 //tempo val mapped
00026 float tempoval;
00027 int clockcount;
00028 int targetnumber;
00029 //ADC SETUP
00030 float adc1; 
00031 float adc2;
00032 float adc3; 
00033 // LED CONTROL 
00034 bool lc;
00035 bool lcshp;
00036 bool ld;
00037 bool ldshp;
00038 bool le;
00039 bool lf;
00040 bool lfshp;
00041 bool lg;
00042 bool lgshp;
00043 bool la;
00044 bool lashp;
00045 bool lb;
00046 bool lsixteenth;
00047 bool leighth;
00048 bool lquater;
00049 bool lhalf;
00050 bool lone;
00051 bool ltwo;
00052 bool lnegtwo;
00053 bool lnegone;
00054 bool lzero;
00055 bool lplusone;
00056 bool lplustwo;
00057 
00058 void updateled(void){
00059     ledlatch = 1;
00060     ledlatch = 0;
00061     leddata = lsixteenth; //LABEL 1/16
00062     ledclock = 1;
00063     ledclock = 0;
00064     leddata = 0;
00065     leddata = leighth; //LABEL 1/8
00066     ledclock = 1;
00067     ledclock = 0;
00068     leddata = 0;
00069     leddata = lquater; //LABEL 1/4
00070     ledclock = 1;
00071     ledclock = 0;
00072     leddata = 0;
00073     leddata = lhalf; //LABEL 1/2
00074     ledclock = 1;
00075     ledclock = 0;
00076     leddata = 0;
00077     leddata = lone; //LABEL 1
00078     ledclock = 1;
00079     ledclock = 0;
00080     leddata = 0;
00081     leddata = ltwo; //LABEL 2
00082     ledclock = 1;
00083     ledclock = 0;
00084     leddata = 0;
00085     leddata = lnegtwo; //LABEL -2
00086     ledclock = 1;
00087     ledclock = 0;
00088     leddata = 0;
00089     leddata = lnegone; //LABEL -1
00090     ledclock = 1;
00091     ledclock = 0;
00092     leddata = 0;
00093     leddata = lzero; //LABEL = 0
00094     ledclock = 1;
00095     ledclock = 0;
00096     leddata = 0;
00097     leddata = lplusone; //LABEL 1
00098     ledclock = 1;
00099     ledclock = 0;
00100     leddata = 0;
00101     leddata = lplustwo; //LABEL 2 
00102     ledclock = 1;
00103     ledclock = 0;
00104     leddata = 0;
00105     leddata = 0; //LABEL no
00106     ledclock = 1;
00107     ledclock = 0;
00108     leddata = 0;
00109     leddata = 1; //LABEL no 
00110     ledclock = 1;
00111     ledclock = 0;
00112     leddata = 0;    
00113     leddata = 1; //LABEL no
00114     ledclock = 1;
00115     ledclock = 0;
00116     leddata = 0;     
00117     leddata = 0; //LABEL no
00118     ledclock = 1;
00119     ledclock = 0;
00120     leddata = 0;  
00121     leddata = lb; //LABEL B
00122     ledclock = 1;
00123     ledclock = 0;
00124     leddata = 0;   
00125     leddata = lashp; //LABEL A#
00126     ledclock = 1;
00127     ledclock = 0;
00128     leddata = 0;       
00129     leddata = la; //LABEL A
00130     ledclock = 1;
00131     ledclock = 0;
00132     leddata = 0; 
00133     leddata = lgshp; //LABEL G# 
00134     ledclock = 1;
00135     ledclock = 0;
00136     leddata = 0; 
00137     leddata = lg; //LABEL G
00138     ledclock = 1;
00139     ledclock = 0;
00140     leddata = 0; 
00141     leddata = lfshp; //LABEL F#
00142     ledclock = 1;
00143     ledclock = 0;
00144     leddata = 0; 
00145     leddata = lf; //LABEL F
00146     ledclock = 1;
00147     ledclock = 0;
00148     leddata = 0; 
00149     leddata = le; //LABEL E
00150     ledclock = 1;
00151     ledclock = 0;
00152     leddata = 0; 
00153     leddata = ldshp; //LABEL D#
00154     ledclock = 1;
00155     ledclock = 0;
00156     leddata = 0; 
00157     leddata = ld; //LABEL D
00158     ledclock = 1;
00159     ledclock = 0;
00160     leddata = 0; 
00161     leddata = lcshp; //LABEL C#
00162     ledclock = 1;
00163     ledclock = 0;
00164     leddata = 0; 
00165     leddata = lc; //LABEL C
00166     ledclock = 1;
00167     ledclock = 0;
00168     leddata = 0; 
00169     
00170     }
00171 void allledon(void){
00172 lc=1;
00173 lcshp=1;
00174 ld=1;
00175 ldshp=1;
00176 le=1;
00177 lf=1;
00178 lfshp=1;
00179 lg=1;
00180 lgshp=1;
00181 la=1;
00182 lashp=1;
00183 lb=1;
00184 lsixteenth=1;
00185 leighth=1;
00186 lquater=1;
00187 lhalf=1;
00188 lone=1;
00189 ltwo=1;
00190 lnegtwo=1;
00191 lnegone=1;
00192 lzero=1;
00193 lplusone=1;
00194 lplustwo=1;
00195 lrun = 0;
00196 lloop = 0;
00197 }
00198 void allledoff(void){
00199 lc=0;
00200 lcshp=0;
00201 ld=0;
00202 ldshp=0;
00203 le=0;
00204 lf=0;
00205 lfshp=0;
00206 lg=0;
00207 lgshp=0;
00208 la=0;
00209 lashp=0;
00210 lb=0;
00211 lsixteenth=0;
00212 leighth=0;
00213 lquater=0;
00214 lhalf=0;
00215 lone=0;
00216 ltwo=0;
00217 lnegtwo=0;
00218 lnegone=0;
00219 lzero=0;
00220 lplusone=0;
00221 lplustwo=0;
00222 lrun = 1;
00223 lloop = 1;
00224 }
00225 void post(void){
00226     allledon();
00227     wait(0.5);
00228     allledoff();
00229     wait(0.5);
00230     allledon();
00231     wait(0.5);
00232     allledoff();
00233     wait(0.5);
00234     allledon();
00235     wait(0.5);
00236     allledoff();
00237     wait(0.5);
00238     
00239     }
00240  void getfaderdata(void){
00241     multiplexa = 0;
00242     adc1 = analog_valuea.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00243     adc1 = adc1 *100;
00244     vc = adc1;
00245     multiplexa = 1;
00246     adc1 = analog_valuea.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00247     adc1 = adc1 *100;
00248     vcshp = adc1;
00249     multiplexa = 2;
00250     adc1 = analog_valuea.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00251     adc1 = adc1 *100;
00252     vd = adc1;
00253     multiplexa = 3;
00254     adc1 = analog_valuea.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00255     adc1 = adc1 *100;
00256     vdshp = adc1;
00257     multiplexa = 4;
00258     adc1 = analog_valuea.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00259     adc1 = adc1 *100;
00260     ve = adc1;
00261     multiplexa = 5;
00262     adc1 = analog_valuea.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00263     adc1 = adc1 *100;
00264     vf = adc1;
00265     multiplexa = 6;
00266     adc1 = analog_valuea.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00267     adc1 = adc1 *100;
00268     vfshp = adc1;
00269     multiplexa = 7;
00270     adc1 = analog_valuea.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00271     adc1 = adc1 *100;
00272     vg = adc1; 
00273     multiplexb = 0;
00274     adc2 = analog_valueb.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00275     adc2 = adc2 *100;
00276     vgshp = adc2;
00277     multiplexb = 1;
00278     adc2 = analog_valueb.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00279     adc2 = adc2 *100;
00280     va = adc2;
00281     multiplexb = 2;
00282     adc2 = analog_valueb.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00283     adc2 = adc2 *100;
00284     vashp = adc2;
00285     multiplexb = 3;
00286     adc2 = analog_valueb.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00287     adc2 = adc2 *100;
00288     vb = adc2;
00289     multiplexb = 4;
00290     adc2 = analog_valueb.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00291     adc2 = (adc2 *255);
00292     vtempo = adc2;
00293     multiplexb = 5;
00294     adc2 = analog_valueb.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00295     adc2 = adc2 *100;
00296     vplustwo = adc2;
00297     multiplexb = 6;
00298     adc2 = analog_valueb.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00299     adc2 = adc2 *100;
00300     vplusone = adc2;
00301     multiplexb = 7;
00302     adc2 = analog_valueb.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00303     adc2 = adc2 *100;
00304     vzero = adc2;
00305     multiplexc = 0;
00306     adc3 = analog_valuec.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00307     adc3 = adc3 *100;
00308     vnegone = adc3;
00309     multiplexc = 1;
00310     adc3 = analog_valuec.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00311     adc3 = adc3 *100;
00312     vnegtwo = adc3;
00313     multiplexc = 2;
00314     adc3 = analog_valuec.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00315     adc3 = adc3 *100;
00316     vtwo = adc3;
00317     multiplexc = 3;
00318     adc3 = analog_valuec.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00319     adc3 = adc3 *100;
00320     vone = adc3;
00321     multiplexc = 4;
00322     adc3 = analog_valuec.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00323     adc3 = adc3 *100;
00324     vhalf = adc3;
00325     multiplexc = 5;
00326     adc3 = analog_valuec.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00327     adc3 = adc3 *100;
00328     vquater = adc3;
00329     multiplexc = 6;
00330     adc3 = analog_valuec.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00331     adc3 = adc3 *100;
00332     veigth = adc3;
00333     multiplexc = 7;
00334     adc3 = analog_valuec.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00335     adc3 = adc3 *100;
00336     vsixthteenth = adc3;
00337 }   
00338 void serialfadervalues(void){
00339     pc.printf("CHA %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f \n\r",vc,vcshp,vd,vdshp,ve,vf,vfshp,vg);
00340     pc.printf("CHC %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f \n\r",vnegone,vnegtwo,vtwo,vone,vhalf,vquater,veigth,vsixthteenth); 
00341     pc.printf("CHB %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f \n\r",vgshp,va,vashp,vb,vtempo,vplustwo,vplusone,vzero); 
00342 }
00343 // SUM OF THE PROABILITIES!!! 
00344 void sumprobabilitynotes(void){
00345     sumnotes = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg+vgshp+va+vashp+vb;
00346     //pc.printf("sum of notes %f \n\r",sumnotes);
00347     sumnotes2 = sumnotes;
00348     }
00349 void sumprobabilityoctives(void){
00350     sumoctives = vplustwo+vplusone+vzero+vnegone+vnegtwo;
00351     //pc.printf("sum of octives %f \n\r",sumoctives);
00352     sumoctives2 = sumoctives;
00353     }
00354 void sumprobabilityduration(void){
00355     sumduration = vtwo+vone+vhalf+vquater+vsixthteenth+veigth;
00356     //pc.printf("sum of duration %f \n\r",sumduration);
00357     sumduration2 = sumduration;
00358     }
00359 //RANDOM GENERATORS!!!!
00360 void randomgeneratenotes(void){
00361     randomnotes=rand()%sumnotes2;
00362     //pc.printf("random notes is %i \n\r",randomnotes);
00363     }
00364 void randomgenerateoctives(void){
00365     randomoctives=rand()%sumoctives2;
00366     //pc.printf("random octives is %i \n\r",randomoctives);
00367     }
00368 void randomgenerateduration(void){
00369     randomduration=rand()%sumduration2;
00370     //pc.printf("random duration is %i \n\r", randomduration);
00371 }
00372 //DERTERNINE THE RANDOM SELECTIONS (REALISE THE PROBABALISED)     
00373 void determinenotes(void){
00374   matchflagnotes = 0;
00375   matchnotelower = 0;
00376   matchnotehigher = vc;
00377   if(randomnotes > 0 && randomnotes < matchnotehigher && matchflagnotes == 0){
00378   probabalisednote = matchnotehigher;
00379   //pc.printf("Proababilised note matched C\n\r");
00380   matchflagnotes = 1;
00381   note = 1;
00382   }
00383   matchnotelower = vc;
00384   matchnotehigher = vc+vcshp;
00385   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00386   probabalisednote = matchnotehigher;
00387   //pc.printf("Proababilised note matched C#\n\r");
00388   matchflagnotes = 1;
00389   note = 2;
00390   }
00391   matchnotelower = vc+vcshp;
00392   matchnotehigher = vc+vcshp+vd;
00393   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00394   probabalisednote = matchnotehigher;
00395   //pc.printf("Proababilised note matched D\n\r");
00396   matchflagnotes = 1;
00397   note = 3;
00398   }
00399   matchnotelower = vc+vcshp+vd;
00400   matchnotehigher = vc+vcshp+vd+vdshp;
00401   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00402   probabalisednote = matchnotehigher;
00403   //pc.printf("Proababilised note matched D#\n\r");
00404   matchflagnotes = 1;
00405   note = 4;
00406   }
00407   matchnotelower = vc+vcshp+vd+vdshp;
00408   matchnotehigher = vc+vcshp+vd+vdshp+ve;
00409   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00410   probabalisednote = matchnotehigher;
00411   //pc.printf("Proababilised note matched E\n\r");
00412   matchflagnotes = 1;
00413   note = 5;
00414   } 
00415   matchnotelower = vc+vcshp+vd+vdshp+ve;
00416   matchnotehigher = vc+vcshp+vd+vdshp+ve+vf;
00417   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00418   probabalisednote = matchnotehigher;
00419   //pc.printf("Proababilised note matched F\n\r");
00420   matchflagnotes = 1;
00421   note = 6;
00422   }
00423   matchnotelower = vc+vcshp+vd+vdshp+ve+vf;
00424   matchnotehigher = vc+vcshp+vd+vdshp+ve+vf+vfshp;
00425   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00426   probabalisednote = matchnotehigher;
00427   //pc.printf("Proababilised note matched F#\n\r");
00428   matchflagnotes = 1;
00429   note = 7;
00430   }
00431   matchnotelower = vc+vcshp+vd+vdshp+ve+vf+vfshp;
00432   matchnotehigher = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg;
00433   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00434   probabalisednote = matchnotehigher;
00435   //pc.printf("Proababilised note matched G\n\r");
00436   matchflagnotes = 1;
00437   note = 8;
00438   }
00439   matchnotelower = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg;
00440   matchnotehigher = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg+vgshp;
00441   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00442   probabalisednote = matchnotehigher;
00443   //pc.printf("Proababilised note matched G#\n\r");
00444   matchflagnotes = 1;
00445   note = 9;
00446   }
00447   matchnotelower = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg+vgshp;
00448   matchnotehigher = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg+vgshp+va;
00449   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00450   probabalisednote = matchnotehigher;
00451   //pc.printf("Proababilised note matched A\n\r");
00452   matchflagnotes = 1;
00453   note = 10;
00454   }
00455   matchnotelower = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg+vgshp+va;
00456   matchnotehigher = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg+vgshp+va+vashp;
00457   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00458   probabalisednote = matchnotehigher;
00459   //pc.printf("Proababilised note matched A#\n\r");
00460   matchflagnotes = 1;
00461   note = 11;
00462   }
00463   matchnotelower = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg+vgshp+va+vashp;
00464   matchnotehigher = vc+vcshp+vd+vdshp+ve+vf+vfshp+vg+vgshp+va+vashp+vb;
00465   if(randomnotes > matchnotelower && randomnotes < matchnotehigher && matchflagnotes == 0){
00466   probabalisednote = matchnotehigher;
00467   //pc.printf("Proababilised note matched B\n\r");
00468   matchflagnotes = 1;
00469   note = 12;
00470   }
00471   if(matchflagnotes == 1){
00472   //pc.printf("NOTE COMP EMGINE COMPLETE \n\r");    
00473   }
00474   if(sumnotes < 1){
00475   note = 0;
00476   }    
00477 }
00478 void determineoctives(void){
00479   matchflagoctive = 0;
00480   matchoctivelower = 0;
00481   matchoctivehigher = vnegtwo;
00482   if(randomoctives > matchoctivelower && randomoctives < matchoctivehigher && matchflagoctive == 0){
00483   probabalisedoctive = matchoctivehigher;
00484   //pc.printf("Proababilised octive matched -2 \n\r");
00485   matchflagoctive = 1;
00486   octive = 1;
00487   }
00488   matchoctivelower = vnegtwo;
00489   matchoctivehigher = vnegtwo+vnegone;
00490   if(randomoctives > matchoctivelower && randomoctives < matchoctivehigher && matchflagoctive == 0){
00491   probabalisedoctive = matchoctivehigher;
00492   //pc.printf("Proababilised octive matched -1 \n\r");
00493   matchflagoctive = 1;
00494   octive = 2;
00495   }
00496   matchoctivelower = vnegtwo+vnegone;
00497   matchoctivehigher = vnegtwo+vnegone+vzero;
00498   if(randomoctives > matchoctivelower && randomoctives < matchoctivehigher && matchflagoctive == 0){
00499   probabalisedoctive = matchoctivehigher;
00500   //pc.printf("Proababilised octive matched 0 \n\r");
00501   matchflagoctive = 1;
00502   octive = 3;
00503   }
00504   matchoctivelower = vnegtwo+vnegone+vzero;
00505   matchoctivehigher = vnegtwo+vnegone+vzero+vplusone;
00506   if(randomoctives > matchoctivelower && randomoctives < matchoctivehigher && matchflagoctive == 0){
00507   probabalisedoctive = matchoctivehigher;
00508   //pc.printf("Proababilised octive matched +1 \n\r");
00509   matchflagoctive = 1;
00510   octive = 4;
00511   }
00512   matchoctivelower = vnegtwo+vnegone+vzero+vplusone;
00513   matchoctivehigher = vnegtwo+vnegone+vzero+vplusone+vplustwo;
00514   if(randomoctives > matchoctivelower && randomoctives < matchoctivehigher && matchflagoctive == 0){
00515   probabalisedoctive = matchoctivehigher;
00516   //pc.printf("Proababilised octive matched +2 \n\r");
00517   matchflagoctive = 1;
00518   octive = 5;
00519   } 
00520   if(matchflagoctive == 1){
00521   //pc.printf("OCTIVES COMP EMGINE COMPLETE \n\r");    
00522   }
00523   if(sumoctives < 50){
00524   octive = 0;
00525   }
00526 }
00527 void determineduration(void){
00528   matchflagduration = 0;
00529   matchdurationlower = 0;
00530   matchdurationhigher = vsixthteenth;
00531   if(randomduration > matchdurationlower && randomduration < matchdurationhigher && matchflagduration == 0){
00532   probabalisedduration = matchdurationhigher;
00533   //pc.printf("Proababilised duration matched 1/16 \n\r");
00534   matchflagduration = 1;
00535   duration = 1;
00536 
00537   }
00538   matchdurationlower = vsixthteenth;
00539   matchdurationhigher = vsixthteenth+veigth;
00540   if(randomduration > matchdurationlower && randomduration < matchdurationhigher && matchflagduration == 0){
00541   probabalisedduration = matchdurationhigher;
00542   //pc.printf("Proababilised duration matched 1/8 \n\r");
00543   matchflagduration = 1;
00544   duration = 2;
00545   }
00546   matchdurationlower = vsixthteenth+veigth;
00547   matchdurationhigher = vsixthteenth+veigth+vquater;
00548   if(randomduration > matchdurationlower && randomduration < matchdurationhigher && matchflagduration == 0){
00549   probabalisedduration = matchdurationhigher;
00550   //pc.printf("Proababilised duration matched 1/4 \n\r");
00551   matchflagduration = 1;
00552   duration = 4;
00553 
00554   }
00555   matchdurationlower = vsixthteenth+veigth+vquater;
00556   matchdurationhigher = vsixthteenth+veigth+vquater+vhalf;
00557   if(randomduration > matchdurationlower && randomduration < matchdurationhigher && matchflagduration == 0){
00558   probabalisedduration = matchdurationhigher;
00559   //pc.printf("Proababilised duration matched 1/2 \n\r");
00560   matchflagduration = 1;
00561   duration = 8;
00562   }
00563   matchdurationlower = vsixthteenth+veigth+vquater+vhalf;
00564   matchdurationhigher = vsixthteenth+veigth+vquater+vhalf+vone;
00565   if(randomduration > matchdurationlower && randomduration < matchdurationhigher && matchflagduration == 0){
00566   probabalisedduration = matchdurationhigher;
00567   //pc.printf("Proababilised duration matched +1 \n\r");
00568   matchflagduration = 1;
00569   duration = 16;
00570   } 
00571   matchdurationlower = vsixthteenth+veigth+vquater+vhalf+vone;
00572   matchdurationhigher = vsixthteenth+veigth+vquater+vhalf+vone+vtwo;
00573   if(randomduration > matchdurationlower && randomduration < matchdurationhigher && matchflagduration == 0){
00574   probabalisedduration = matchdurationhigher;
00575   //pc.printf("Proababilised duration matched +2 \n\r");
00576   matchflagduration = 1;
00577   duration = 32;
00578   } 
00579   if(matchflagduration == 1){
00580   //pc.printf("DURATION COMP EMGINE COMPLETE \n\r");    
00581   }
00582   if(sumduration < 1){
00583   duration = 0;
00584   }
00585 }
00586 //tempo
00587 float map(float in, float inMin, float inMax, float outMin, float outMax) {
00588   // check it's within the range
00589   if (inMin<inMax) { 
00590     if (in <= inMin) 
00591       return outMin;
00592     if (in >= inMax)
00593       return outMax;
00594   } else {  // cope with input range being backwards.
00595     if (in >= inMin) 
00596       return outMin;
00597     if (in <= inMax)
00598       return outMax;
00599   }
00600   // calculate how far into the range we are
00601   float scale = (in-inMin)/(inMax-inMin);
00602   // calculate the output.
00603   return outMin + scale*(outMax-outMin);
00604 }
00605 void gettempodata(void){
00606   tempoval = map(vtempo,0,255,255,32);
00607 }
00608 void debugtempodata(void){
00609   pc.printf("unmapped %f mapped %f\n\r",vtempo,tempoval);
00610 }
00611 void outputdecision(void){
00612     if(note == 1){
00613         lc = 1;
00614     //int duration = 0; //1=1/16 2=1/8 3=1/4 4=1/2 5=1 6=2 
00615 
00616     }
00617     else if(note == 2){
00618         lcshp = 1;
00619     }
00620     else if(note == 3){
00621         ld = 1;
00622     }
00623     else if(note == 4){
00624         ldshp = 1;
00625     }
00626     else if(note == 5){
00627         le = 1;
00628     }
00629     else if(note == 6){
00630         lf = 1;
00631     }
00632     else if(note == 7){
00633         lfshp = 1;
00634     }
00635     else if(note == 8){
00636         lg = 1;
00637     }
00638     else if(note == 9){
00639         lgshp = 1;
00640     }
00641     else if(note == 10){
00642         la = 1;
00643     }
00644     else if(note == 11){
00645         lashp = 1;
00646     }
00647     else if(note == 12){
00648         lb = 1;
00649     }
00650     else{
00651      lc = 0;
00652      lcshp = 0;
00653      ld= 0;
00654      ldshp= 0;
00655      le= 0;
00656      lf= 0;
00657      lfshp= 0;
00658      lg= 0;
00659      lgshp= 0;
00660      la= 0;
00661      lashp= 0;
00662      lb= 0;
00663     }
00664     if(octive == 1){
00665         lnegtwo = 1;
00666     }
00667     else if(octive == 2){
00668         lnegone = 1;
00669     }
00670     else if(octive == 3){
00671         lzero = 1;
00672     }
00673     else if(octive == 4){
00674         lplusone = 1;
00675     }
00676     else if(octive == 5){
00677         lplustwo = 1;
00678     }
00679     else {
00680         lnegtwo = 0;
00681         lnegone = 0;
00682         lzero = 0;
00683         lplusone = 0;
00684         lplustwo = 0;
00685     }
00686     if(duration == 1){
00687         lsixteenth = 1;
00688     }
00689     else if(duration == 2){
00690         leighth = 1;
00691     }
00692     else if(duration == 4){
00693         lquater = 1;
00694     }
00695     else if(duration == 8){
00696         lhalf = 1;
00697     }
00698     else if(duration == 16){
00699         lone = 1;
00700     }
00701     else if(duration == 32){
00702         ltwo = 1;
00703     }
00704     else {
00705      lsixteenth = 0;
00706      leighth = 0;
00707      lquater = 0;
00708      lhalf = 0;
00709      lone = 0;
00710      ltwo = 0;
00711     }    
00712 }
00713 void senddacout(void){
00714     //octive 0 
00715       updateled();
00716     if(note == 1 && octive == 1){ 
00717     cs = 1;
00718     cs = 0;
00719     dac.write(0x30);
00720     dac.write(0x00);
00721     dac.write(0x00);
00722     cs = 1;
00723     pc.printf("N2O4\n\r");
00724         }
00725     else if(note == 2 && octive == 1){ 
00726      cs = 1;
00727     cs = 0;
00728     dac.write(0x30);
00729     dac.write(0x03);
00730     dac.write(0x0C);
00731     cs = 1;
00732     pc.printf("N2O4\n\r");
00733         }
00734     else if(note == 3 && octive == 1){ 
00735     cs = 1;
00736     cs = 0;
00737     dac.write(0x30);
00738     dac.write(0x06);
00739     dac.write(0x18);
00740     cs = 1;
00741     pc.printf("N2O4\n\r");
00742         }
00743     else if(note == 4 && octive == 1){ 
00744     cs = 1;
00745     cs = 0;
00746     dac.write(0x30);
00747     dac.write(0x09);
00748     dac.write(0x24);
00749     cs = 1;
00750     pc.printf("N2O4\n\r");
00751     }
00752     else if(note == 5 && octive == 1){  
00753     cs = 1;
00754     cs = 0;
00755     dac.write(0x30);
00756     dac.write(0x0C);
00757     dac.write(0x2F);
00758     cs = 1;
00759     pc.printf("N2O4\n\r");
00760     }
00761     else if(note == 6 && octive == 1){  
00762     cs = 1;
00763     cs = 0;
00764     dac.write(0x30);
00765     dac.write(0x0F);
00766     dac.write(0x3B);
00767     cs = 1;
00768     pc.printf("N2O4\n\r");
00769     }
00770     else if(note == 7 && octive == 1){  
00771     cs = 1;
00772     cs = 0;
00773     dac.write(0x30);
00774     dac.write(0x12);
00775     dac.write(0x47);
00776     cs = 1;
00777     pc.printf("N2O4\n\r");
00778     }
00779     else if(note == 8 && octive == 1){  
00780     cs = 1;
00781     cs = 0;
00782     dac.write(0x30);
00783     dac.write(0x15);
00784     dac.write(0x53);
00785     cs = 1;
00786     pc.printf("N2O4\n\r");
00787     }
00788     else if(note == 9 && octive == 1){  
00789     cs = 1;
00790     cs = 0;
00791     dac.write(0x30);
00792     dac.write(0x18);
00793     dac.write(0x5F);
00794     cs = 1;
00795     pc.printf("N2O4\n\r");
00796     }
00797     else if(note == 10 && octive == 1){  
00798     cs = 1;
00799     cs = 0;
00800     dac.write(0x30);
00801     dac.write(0x1B);
00802     dac.write(0x6B);
00803     cs = 1;
00804     pc.printf("N2O4\n\r");
00805     }
00806     else if(note == 11 && octive == 1){  
00807     cs = 1;
00808     cs = 0;
00809     dac.write(0x30);
00810     dac.write(0x1E);
00811     dac.write(0x77);
00812     cs = 1;
00813     pc.printf("N2O4\n\r");
00814     }
00815     else if(note == 12 && octive == 1){  
00816     cs = 1;
00817     cs = 0;
00818     dac.write(0x30);
00819     dac.write(0x21);
00820     dac.write(0x83);
00821     cs = 1;
00822     pc.printf("N2O4\n\r");
00823     } 
00824     //OCTIVE -1 
00825     else if(note == 1 && octive == 2){ 
00826     cs = 1;
00827     cs = 0;
00828     dac.write(0x30);
00829     dac.write(0x24);
00830     dac.write(0x8E);
00831     cs = 1;
00832     pc.printf("N2O4\n\r");
00833     }
00834     else if(note == 2 && octive == 2){ 
00835     cs = 1;
00836     cs = 0;
00837     dac.write(0x30);
00838     dac.write(0x27);
00839     dac.write(0x9A);
00840     cs = 1;
00841     pc.printf("N2O4\n\r");
00842     }
00843     else if(note == 3 && octive == 2){  
00844     cs = 1;
00845     cs = 0;
00846     dac.write(0x30);
00847     dac.write(0x2A);
00848     dac.write(0xA6);
00849     cs = 1;
00850     pc.printf("N2O4\n\r");
00851     }
00852     else if(note == 4 && octive == 2){  
00853     cs = 1;
00854     cs = 0;
00855     dac.write(0x30);
00856     dac.write(0x2D);
00857     dac.write(0xB2);
00858     cs = 1;
00859     pc.printf("N2O4\n\r");
00860     }
00861     else if(note == 5 && octive == 2){  
00862     cs = 1;
00863     cs = 0;
00864     dac.write(0x30);
00865     dac.write(0x30);
00866     dac.write(0xBE);
00867     cs = 1;
00868     pc.printf("N2O4\n\r");
00869     }
00870     else if(note == 6 && octive == 2){  
00871     cs = 1;
00872     cs = 0;
00873     dac.write(0x30);
00874     dac.write(0x33);
00875     dac.write(0xCA);
00876     cs = 1;
00877     pc.printf("N2O4\n\r");
00878     }
00879     else if(note == 7 && octive == 2){  
00880     cs = 1;
00881     cs = 0;
00882     dac.write(0x30);
00883     dac.write(0x36);
00884     dac.write(0xD6);
00885     cs = 1;
00886     pc.printf("N2O4\n\r");
00887     }
00888     else if(note == 8 && octive == 2){  
00889     cs = 1;
00890     cs = 0;
00891     dac.write(0x30);
00892     dac.write(0x39);
00893     dac.write(0xE2);
00894     cs = 1;
00895     pc.printf("N2O4\n\r");
00896     }
00897     else if(note == 9 && octive == 2){  
00898     cs = 1;
00899     cs = 0;
00900     dac.write(0x30);
00901     dac.write(0x3C);
00902     dac.write(0xED);
00903     cs = 1;
00904     pc.printf("N2O4\n\r");
00905     }
00906     else if(note == 10 && octive == 2){  
00907     cs = 1;
00908     cs = 0;
00909     dac.write(0x30);
00910     dac.write(0x3F);
00911     dac.write(0xF9);
00912     cs = 1;
00913     pc.printf("N2O4\n\r");
00914     }
00915     else if(note == 11 && octive == 2){ 
00916     cs = 1;
00917     cs = 0;
00918     dac.write(0x30);
00919     dac.write(0x43);
00920     dac.write(0x05);
00921     cs = 1;
00922     pc.printf("N2O4\n\r");
00923     }
00924     else if(note == 12 && octive == 2){  
00925     cs = 1;
00926     cs = 0;
00927     dac.write(0x30);
00928     dac.write(0x46);
00929     dac.write(0x11);
00930     cs = 1;
00931     pc.printf("N2O4\n\r");
00932     }
00933     //octive2
00934     //OCTIVE 1 
00935     else if(note == 1 && octive == 3){ 
00936     cs = 1;
00937     cs = 0;
00938     dac.write(0x30);
00939     dac.write(0x49);
00940     dac.write(0x1D);
00941     cs = 1;
00942     pc.printf("N2O4\n\r");
00943     }
00944     else if(note == 2 && octive == 3){ 
00945     cs = 1;
00946     cs = 0;
00947     dac.write(0x30);
00948     dac.write(0x4C);
00949     dac.write(0x29);
00950     cs = 1;
00951     pc.printf("N2O4\n\r");
00952     }
00953     else if(note == 3 && octive == 3){  
00954     cs = 1;
00955     cs = 0;
00956     dac.write(0x30);
00957     dac.write(0x4F);
00958     dac.write(0x35);
00959     cs = 1;
00960     pc.printf("N2O4\n\r");
00961     }
00962     else if(note == 4 && octive == 3){  
00963     cs = 1;
00964     cs = 0;
00965     dac.write(0x30);
00966     dac.write(0x52);
00967     dac.write(0x40);
00968     cs = 1;
00969     pc.printf("N2O4\n\r");
00970     }
00971     else if(note == 5 && octive == 3){  
00972     cs = 1;
00973     cs = 0;
00974     dac.write(0x30);
00975     dac.write(0x55);
00976     dac.write(0x4C);
00977     cs = 1;
00978     pc.printf("N2O4\n\r");
00979     }
00980     else if(note == 6 && octive == 3){  
00981     cs = 1;
00982     cs = 0;
00983     dac.write(0x30);
00984     dac.write(0x58);
00985     dac.write(0x58);
00986     cs = 1;
00987     pc.printf("N2O4\n\r");
00988     }
00989     else if(note == 7 && octive == 3){  
00990     cs = 1;
00991     cs = 0;
00992     dac.write(0x30);
00993     dac.write(0x5B);
00994     dac.write(0x64);
00995     cs = 1;
00996     pc.printf("N2O4\n\r");
00997     }
00998     else if(note == 8 && octive == 3){  
00999     cs = 1;
01000     cs = 0;
01001     dac.write(0x30);
01002     dac.write(0x5E);
01003     dac.write(0x70);
01004     cs = 1;
01005     pc.printf("N2O4\n\r");
01006     }
01007     else if(note == 9 && octive == 3){  
01008     cs = 1;
01009     cs = 0;
01010     dac.write(0x30);
01011     dac.write(0x61);
01012     dac.write(0x7C);
01013     cs = 1;
01014     pc.printf("N2O4\n\r");
01015     }
01016     else if(note == 10 && octive == 3){  
01017     cs = 1;
01018     cs = 0;
01019     dac.write(0x30);
01020     dac.write(0x64);
01021     dac.write(0x88);
01022     cs = 1;
01023     pc.printf("N2O4\n\r");
01024     }
01025     else if(note == 11 && octive == 3){ 
01026     cs = 1;
01027     cs = 0;
01028     dac.write(0x30);
01029     dac.write(0x67);
01030     dac.write(0x94);
01031     cs = 1;
01032     pc.printf("N2O4\n\r");
01033     }
01034     else if(note == 12 && octive == 3){  
01035     cs = 1;
01036     cs = 0;
01037     dac.write(0x30);
01038     dac.write(0x6A);
01039     dac.write(0x9F);
01040     cs = 1;
01041     pc.printf("N2O4\n\r");
01042     }    
01043     else if(note == 1 && octive == 4){ 
01044     cs = 1;
01045     cs = 0;
01046     dac.write(0x30);
01047     dac.write(0x6D);
01048     dac.write(0xAB);
01049     cs = 1;
01050     pc.printf("N2O4\n\r");
01051     }
01052     else if(note == 2 && octive == 4){ 
01053     cs = 1;
01054     cs = 0;
01055     dac.write(0x30);
01056     dac.write(0x70);
01057     dac.write(0xB7);
01058     cs = 1;
01059     pc.printf("N2O4\n\r");
01060     }
01061     else if(note == 3 && octive == 4){  
01062     cs = 1;
01063     cs = 0;
01064     dac.write(0x30);
01065     dac.write(0x73);
01066     dac.write(0xC3);
01067     cs = 1;
01068     pc.printf("N2O4\n\r");
01069     }
01070     else if(note == 4 && octive == 4){  
01071     cs = 1;
01072     cs = 0;
01073     dac.write(0x30);
01074     dac.write(0x76);
01075     dac.write(0xCF);
01076     cs = 1;
01077     pc.printf("N2O4\n\r");
01078     }
01079     else if(note == 5 && octive == 4){  
01080     cs = 1;
01081     cs = 0;
01082     dac.write(0x30);
01083     dac.write(0x79);
01084     dac.write(0xDB);
01085     cs = 1;
01086     pc.printf("N2O4\n\r");
01087     }
01088     else if(note == 6 && octive == 4){  
01089     cs = 1;
01090     cs = 0;
01091     dac.write(0x30);
01092     dac.write(0x7C);
01093     dac.write(0xE7);
01094     cs = 1;
01095     pc.printf("N2O4\n\r");
01096     }
01097     else if(note == 7 && octive == 4){  
01098     cs = 1;
01099     cs = 0;
01100     dac.write(0x30);
01101     dac.write(0x7F);
01102     dac.write(0xF2);
01103     cs = 1;
01104     pc.printf("N2O4\n\r");
01105     }
01106     else if(note == 8 && octive == 4){  
01107     cs = 1;
01108     cs = 0;
01109     dac.write(0x30);
01110     dac.write(0x82);
01111     dac.write(0xFE);
01112     cs = 1;
01113     pc.printf("N2O4\n\r");
01114     }
01115     else if(note == 9 && octive == 4){  
01116     cs = 1;
01117     cs = 0;
01118     dac.write(0x30);
01119     dac.write(0x86);
01120     dac.write(0x0A);
01121     cs = 1;
01122     pc.printf("N2O4\n\r");
01123     }
01124     else if(note == 10 && octive == 4){  
01125     cs = 1;
01126     cs = 0;
01127     dac.write(0x30);
01128     dac.write(0x89);
01129     dac.write(0x16);
01130     cs = 1;
01131     pc.printf("N2O4\n\r");
01132     }
01133     else if(note == 11 && octive == 4){ 
01134     cs = 1;
01135     cs = 0;
01136     dac.write(0x30);
01137     dac.write(0x8C);
01138     dac.write(0x22);
01139     cs = 1;
01140     pc.printf("N2O4\n\r");
01141     }
01142     else if(note == 12 && octive == 4){  
01143     cs = 1;
01144     cs = 0;
01145     dac.write(0x30);
01146     dac.write(0x8F);
01147     dac.write(0x2E);
01148     cs = 1;
01149     pc.printf("N2O4\n\r");
01150     }
01151     else if(note == 1 && octive == 5){ 
01152     cs = 1;
01153     cs = 0;
01154     dac.write(0x30);
01155     dac.write(0x92);
01156     dac.write(0x3A);
01157     cs = 1;
01158     pc.printf("N2O4\n\r");
01159         }
01160     else if(note == 2 && octive == 5){ 
01161      cs = 1;
01162     cs = 0;
01163     dac.write(0x30);
01164     dac.write(0x95);
01165     dac.write(0x46);
01166     cs = 1;
01167     pc.printf("N2O4\n\r");
01168         }
01169     else if(note == 3 && octive == 5){ 
01170     cs = 1;
01171     cs = 0;
01172     dac.write(0x30);
01173     dac.write(0x98);
01174     dac.write(0x51);
01175     cs = 1;
01176     pc.printf("N2O4\n\r");
01177         }
01178     else if(note == 4 && octive == 5){ 
01179     cs = 1;
01180     cs = 0;
01181     dac.write(0x30);
01182     dac.write(0x9B);
01183     dac.write(0x5D);
01184     cs = 1;
01185     pc.printf("N2O4\n\r");
01186     }
01187     else if(note == 5 && octive == 5){  
01188     cs = 1;
01189     cs = 0;
01190     dac.write(0x30);
01191     dac.write(0x9E);
01192     dac.write(0x69);
01193     cs = 1;
01194     pc.printf("N2O4\n\r");
01195     }
01196     else if(note == 6 && octive == 5){  
01197     cs = 1;
01198     cs = 0;
01199     dac.write(0x30);
01200     dac.write(0xA1);
01201     dac.write(0x75);
01202     cs = 1;
01203     pc.printf("N2O4\n\r");
01204     }
01205     else if(note == 7 && octive == 5){  
01206     cs = 1;
01207     cs = 0;
01208     dac.write(0x30);
01209     dac.write(0xA4);
01210     dac.write(0x81);
01211     cs = 1;
01212     pc.printf("N2O4\n\r");
01213     }
01214     else if(note == 8 && octive == 5){  
01215     cs = 1;
01216     cs = 0;
01217     dac.write(0x30);
01218     dac.write(0xA7);
01219     dac.write(0x8D);
01220     cs = 1;
01221     pc.printf("N2O4\n\r");
01222     }
01223     else if(note == 9 && octive == 5){  
01224     cs = 1;
01225     cs = 0;
01226     dac.write(0x30);
01227     dac.write(0xAA);
01228     dac.write(0x99);
01229     cs = 1;
01230     pc.printf("N2O4\n\r");
01231     }
01232     else if(note == 10 && octive == 5){  
01233     cs = 1;
01234     cs = 0;
01235     dac.write(0x30);
01236     dac.write(0xAD);
01237     dac.write(0xA5);
01238     cs = 1;
01239     pc.printf("N2O4\n\r");
01240     }
01241     else if(note == 11 && octive == 5){  
01242     cs = 1;
01243     cs = 0;
01244     dac.write(0x30);
01245     dac.write(0xB0);
01246     dac.write(0xB0);
01247     cs = 1;
01248     pc.printf("N2O4\n\r");
01249     }
01250     else if(note == 12 && octive == 5){  
01251     cs = 1;
01252     cs = 0;
01253     dac.write(0x30);
01254     dac.write(0xB3);
01255     dac.write(0xBC);
01256     cs = 1;
01257     pc.printf("N2O4\n\r");
01258     }
01259     else if(note == 1 && octive == 6){ 
01260     cs = 1;
01261     cs = 0;
01262     dac.write(0x30);
01263     dac.write(0xB6);
01264     dac.write(0xC8);
01265     cs = 1;
01266     pc.printf("N2O4\n\r");
01267         }
01268     else if(note == 2 && octive == 6){ 
01269      cs = 1;
01270     cs = 0;
01271     dac.write(0x30);
01272     dac.write(0xB9);
01273     dac.write(0xD4);
01274     cs = 1;
01275     pc.printf("N2O4\n\r");
01276         }
01277     else if(note == 3 && octive == 6){ 
01278     cs = 1;
01279     cs = 0;
01280     dac.write(0x30);
01281     dac.write(0xBC);
01282     dac.write(0xE0);
01283     cs = 1;
01284     pc.printf("N2O4\n\r");
01285         }
01286     else if(note == 4 && octive == 6){ 
01287     cs = 1;
01288     cs = 0;
01289     dac.write(0x30);
01290     dac.write(0xBF);
01291     dac.write(0xEC);
01292     cs = 1;
01293     pc.printf("N2O4\n\r");
01294     }
01295     else if(note == 5 && octive == 6){  
01296     cs = 1;
01297     cs = 0;
01298     dac.write(0x30);
01299     dac.write(0xC2);
01300     dac.write(0xF8);
01301     cs = 1;
01302     pc.printf("N2O4\n\r");
01303     }
01304     else if(note == 6 && octive == 6){  
01305     cs = 1;
01306     cs = 0;
01307     dac.write(0x30);
01308     dac.write(0xC6);
01309     dac.write(0x03);
01310     cs = 1;
01311     pc.printf("N2O4\n\r");
01312     }
01313     else if(note == 7 && octive == 6){  
01314     cs = 1;
01315     cs = 0;
01316     dac.write(0x30);
01317     dac.write(0xC9);
01318     dac.write(0x0F);
01319     cs = 1;
01320     pc.printf("N2O4\n\r");
01321     }
01322     else if(note == 8 && octive == 6){  
01323     cs = 1;
01324     cs = 0;
01325     dac.write(0x30);
01326     dac.write(0xCC);
01327     dac.write(0x1B);
01328     cs = 1;
01329     pc.printf("N2O4\n\r");
01330     }
01331     else if(note == 9 && octive == 6){  
01332     cs = 1;
01333     cs = 0;
01334     dac.write(0x30);
01335     dac.write(0xCF);
01336     dac.write(0x27);
01337     cs = 1;
01338     pc.printf("N2O4\n\r");
01339     }
01340     else if(note == 10 && octive == 6){  
01341     cs = 1;
01342     cs = 0;
01343     dac.write(0x30);
01344     dac.write(0xD2);
01345     dac.write(0x33);
01346     cs = 1;
01347     pc.printf("N2O4\n\r");
01348     }
01349     else if(note == 11 && octive == 6){  
01350     cs = 1;
01351     cs = 0;
01352     dac.write(0x30);
01353     dac.write(0xD5);
01354     dac.write(0x3F);
01355     cs = 1;
01356     pc.printf("N2O4\n\r");
01357     }
01358     else if(note == 12 && octive == 6){  
01359     cs = 1;
01360     cs = 0;
01361     dac.write(0x30);
01362     dac.write(0xD8);
01363     dac.write(0x4B);
01364     cs = 1;
01365     pc.printf("N2O4\n\r");
01366     }
01367     else if(note == 1 && octive == 7){ 
01368     cs = 1;
01369     cs = 0;
01370     dac.write(0x30);
01371     dac.write(0xDB);
01372     dac.write(0x57);
01373     cs = 1;
01374     pc.printf("N2O4\n\r");
01375         }
01376     else if(note == 2 && octive == 7){ 
01377      cs = 1;
01378     cs = 0;
01379     dac.write(0x30);
01380     dac.write(0xDE);
01381     dac.write(0x62);
01382     cs = 1;
01383     pc.printf("N2O4\n\r");
01384         }
01385     else if(note == 3 && octive == 7){ 
01386     cs = 1;
01387     cs = 0;
01388     dac.write(0x30);
01389     dac.write(0xE1);
01390     dac.write(0x6E);
01391     cs = 1;
01392     pc.printf("N2O4\n\r");
01393         }
01394     else if(note == 4 && octive == 7){ 
01395     cs = 1;
01396     cs = 0;
01397     dac.write(0x30);
01398     dac.write(0xE4);
01399     dac.write(0x7A);
01400     cs = 1;
01401     pc.printf("N2O4\n\r");
01402     }
01403     else if(note == 5 && octive == 7){  
01404     cs = 1;
01405     cs = 0;
01406     dac.write(0x30);
01407     dac.write(0xE7);
01408     dac.write(0x86);
01409     cs = 1;
01410     pc.printf("N2O4\n\r");
01411     }
01412     else if(note == 6 && octive == 7){  
01413     cs = 1;
01414     cs = 0;
01415     dac.write(0x30);
01416     dac.write(0xF5);
01417     dac.write(0xEA);
01418     cs = 1;
01419     pc.printf("N2O4\n\r");
01420     }
01421     else if(note == 7 && octive == 7){  
01422     cs = 1;
01423     cs = 0;
01424     dac.write(0x30);
01425     dac.write(0xED);
01426     dac.write(0x9E);
01427     cs = 1;
01428     pc.printf("N2O4\n\r");
01429     }
01430     else if(note == 8 && octive == 7){  
01431     cs = 1;
01432     cs = 0;
01433     dac.write(0x30);
01434     dac.write(0xF0);
01435     dac.write(0xAA);
01436     cs = 1;
01437     pc.printf("N2O4\n\r");
01438     }
01439     else if(note == 9 && octive == 7){  
01440     cs = 1;
01441     cs = 0;
01442     dac.write(0x30);
01443     dac.write(0xF3);
01444     dac.write(0xB6);
01445     cs = 1;
01446     pc.printf("N2O4\n\r");
01447     }
01448     else if(note == 10 && octive == 7){  
01449     cs = 1;
01450     cs = 0;
01451     dac.write(0x30);
01452     dac.write(0xA5);
01453     dac.write(0xF6);
01454     cs = 1;
01455     pc.printf("N2O4\n\r");
01456     }
01457     else if(note == 11 && octive == 7){  
01458     cs = 1;
01459     cs = 0;
01460     dac.write(0x30);
01461     dac.write(0xF9);
01462     dac.write(0xCD);
01463     cs = 1;
01464     pc.printf("N2O4\n\r");
01465     }
01466     else if(note == 12 && octive == 7){  
01467     cs = 1;
01468     cs = 0;
01469     dac.write(0x30);
01470     dac.write(0xFC);
01471     dac.write(0xD9);
01472     cs = 1;
01473     pc.printf("N2O4\n\r");
01474     }
01475     else if(note == 1 && octive == 8){
01476     cs = 1;
01477     cs = 0;
01478     dac.write(0x30);
01479     dac.write(0xFF);
01480     dac.write(0xE5);
01481     cs = 1;
01482     }        
01483     }
01484 #endif