George Cochrane
/
DrumMachine
very preliminary code, pins clearly havent been chosen yet!
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "readknobs.h" 00003 #include "trigger.h" 00004 #include "TextLCD.h" 00005 00006 TextLCD lcd(PTA1, PTA2, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD20x4); // rs, e, d4-d7 00007 00008 //Analog Ins 00009 AnalogIn tmp(PTC2); //Tempo Potentiometer 00010 AnalogIn sw(PTC2); //Swing Potentiometer 00011 AnalogIn fill(PTC2); //Fill Potentiometer 00012 00013 //Outputs to Drum Noises 00014 DigitalOut Kick(PTC6); 00015 DigitalOut Snare(PTC10); 00016 DigitalOut HHOpen(PTC11); 00017 DigitalOut HHClosed(PTC6); 00018 DigitalOut HiTom(PTC10); 00019 DigitalOut LoTom(PTC11); 00020 DigitalOut Clap(PTC10); 00021 DigitalOut Block(PTC11); 00022 00023 //Detectors 00024 DigitalIn doubletime(PTC2); //Doubles the tempo 00025 DigitalIn enable(PTC2); //The GO switch 00026 DigitalIn threetime(PTC2); //Causes only first 6 beats to play 00027 DigitalIn KICK(PTC6); 00028 DigitalIn SNARE(PTC10); 00029 DigitalIn HHOPEN(PTC11); 00030 DigitalIn HHCLOSED(PTC6); 00031 DigitalIn HITOM(PTC10); 00032 DigitalIn LOTOM(PTC11); 00033 DigitalIn CLAP(PTC10); 00034 DigitalIn BLOCK(PTC23); 00035 00036 //Beats 00037 DigitalOut Beat1(PTC2); 00038 DigitalOut Beat2(PTC2); 00039 DigitalOut Beat3(PTC2); 00040 DigitalOut Beat4(PTC2); 00041 DigitalOut Beat5(PTC2); 00042 DigitalOut Beat6(PTC2); 00043 DigitalOut Beat7(PTC2); 00044 DigitalOut Beat8(PTC2); 00045 00046 //GLOBAL Variables 00047 int pulse = 4; //Pulse length in ms 00048 int mintempo = 60; //Minimum (normal time) tempo 00049 int maxtempo = 130; //Maximum (non doubletime) tempo 00050 int tempo; 00051 int swing; 00052 int beat; 00053 00054 00055 int main() 00056 { 00057 00058 while (1) 00059 { 00060 readknobs(); 00061 wait_ms(10); 00062 while (enable==1) 00063 { 00064 beat=0; 00065 00066 00067 while (beat++ < 8) 00068 { 00069 00070 readknobs(); 00071 trigger(); 00072 00073 } 00074 00075 } 00076 } 00077 00078 } 00079
Generated on Fri Jul 22 2022 08:54:45 by 1.7.2