very preliminary code, pins clearly havent been chosen yet!

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers readknobs.cpp Source File

readknobs.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #include "readknobs.h"
00004 
00005 //Declare necessary variables
00006 extern int tempo;
00007 extern int swing;
00008 extern int mintempo;
00009 extern int maxtempo;
00010 
00011 void readknobs()        //Function Definition
00012 {
00013 
00014 // SWING CALCULATION
00015 
00016 int a = sw.read() * 10;     //Make the analog read an integer from 0-10
00017 
00018     switch (a)              //Segmented solution to each case
00019     {
00020     case 0: swing = -150;
00021     case 1: swing = -150;
00022     case 2: swing = -100;
00023     case 3: swing = -60;
00024     case 4:                 //
00025     case 5:                 // Note, plenty of 0 swing to prevent accidental swing
00026     case 6: swing = 0;      //
00027     case 7: swing = 60;
00028     case 8: swing = 100;
00029     case 9: swing = 100;
00030     case 10: swing = 150;
00031     }
00032     
00033 // TEMPO CALCULATION
00034 
00035     tempo = mintempo + (maxtempo-mintempo)*tmp.read_u16() / 65535;  //Tempo as the analog read percentage multiplied by tempo range
00036     
00037     tempo = (doubletime) ? 2*tempo : tempo;                //Double the tempo if doubletime==1
00038     
00039 // DISPLAY INFO
00040 char signature[]="x/4";
00041 if (threetime==0)
00042 {
00043 signature[0]= '4';
00044 }
00045 else
00046 {
00047 signature[0]= '3';
00048 }
00049 
00050 char percentage = 37;
00051 
00052 lcd.cls();
00053 lcd.locate(0,0);
00054 lcd.printf("%d bpm", tempo);
00055 lcd.locate(1,0);
00056 lcd.printf("Swing: %d %c", swing, percentage);
00057 lcd.locate(2,0);
00058 lcd.printf("TimeSig: %s", signature);
00059 }