George Cochrane
/
DrumMachine
very preliminary code, pins clearly havent been chosen yet!
Revision 1:0404e9aa397f, committed 2013-07-02
- Comitter:
- gcme93
- Date:
- Tue Jul 02 17:50:52 2013 +0000
- Parent:
- 0:438bb4b2ba51
- Commit message:
- Very preliminary code, pins clearly not chosen yet!
Changed in this revision
--- a/main.cpp Tue Jul 02 09:16:17 2013 +0000 +++ b/main.cpp Tue Jul 02 17:50:52 2013 +0000 @@ -1,6 +1,9 @@ #include "mbed.h" #include "readknobs.h" #include "trigger.h" +#include "TextLCD.h" + +TextLCD lcd(PTA1, PTA2, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD20x4); // rs, e, d4-d7 //Analog Ins AnalogIn tmp(PTC2); //Tempo Potentiometer @@ -40,6 +43,7 @@ DigitalOut Beat7(PTC2); DigitalOut Beat8(PTC2); +//GLOBAL Variables int pulse = 4; //Pulse length in ms int mintempo = 60; //Minimum (normal time) tempo int maxtempo = 130; //Maximum (non doubletime) tempo @@ -54,6 +58,7 @@ while (1) { readknobs(); + wait_ms(10); while (enable==1) { beat=0;
--- a/readknobs.cpp Tue Jul 02 09:16:17 2013 +0000 +++ b/readknobs.cpp Tue Jul 02 17:50:52 2013 +0000 @@ -2,32 +2,28 @@ #include "TextLCD.h" #include "readknobs.h" +//Declare necessary variables extern int tempo; extern int swing; extern int mintempo; extern int maxtempo; -int k; - -TextLCD lcd(PTA1, PTA2, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD20x4); // rs, e, d4-d7 - - -void readknobs() +void readknobs() //Function Definition { // SWING CALCULATION -int a = sw.read() * 10; +int a = sw.read() * 10; //Make the analog read an integer from 0-10 - switch (a) + switch (a) //Segmented solution to each case { case 0: swing = -150; case 1: swing = -150; case 2: swing = -100; case 3: swing = -60; - case 4: - case 5: - case 6: swing = 0; + case 4: // + case 5: // Note, plenty of 0 swing to prevent accidental swing + case 6: swing = 0; // case 7: swing = 60; case 8: swing = 100; case 9: swing = 100; @@ -36,12 +32,21 @@ // TEMPO CALCULATION - tempo = mintempo + (maxtempo-mintempo)*tmp.read_u16() / 65535; + tempo = mintempo + (maxtempo-mintempo)*tmp.read_u16() / 65535; //Tempo as the analog read percentage multiplied by tempo range - tempo = (doubletime) ? 2*tempo : tempo; + tempo = (doubletime) ? 2*tempo : tempo; //Double the tempo if doubletime==1 // DISPLAY INFO -char signature = (k==1) ? 3/4 : 4/4; +char signature[]="x/4"; +if (threetime==0) +{ +signature[0]= '4'; +} +else +{ +signature[0]= '3'; +} + char percentage = 37; lcd.cls();
--- a/readknobs.h Tue Jul 02 09:16:17 2013 +0000 +++ b/readknobs.h Tue Jul 02 17:50:52 2013 +0000 @@ -1,8 +1,10 @@ #include "mbed.h" - +#include "TextLCD.h" extern AnalogIn sw; extern AnalogIn tmp; extern DigitalIn doubletime; +extern DigitalIn threetime; +extern TextLCD lcd; void readknobs(); \ No newline at end of file
--- a/trigger.cpp Tue Jul 02 09:16:17 2013 +0000 +++ b/trigger.cpp Tue Jul 02 17:50:52 2013 +0000 @@ -6,6 +6,7 @@ unsigned int periododd; unsigned int periodeven; + void process(void) { Kick = (KICK==1)? 1:0;
--- a/trigger.h Tue Jul 02 09:16:17 2013 +0000 +++ b/trigger.h Tue Jul 02 17:50:52 2013 +0000 @@ -1,9 +1,11 @@ #include "mbed.h" +#include "TextLCD.h" extern int pulse; extern int tempo; extern int swing; extern int beat; +extern TextLCD lcd; //Drum Noises extern DigitalOut Kick;