killingzoe
Member
Hi to everyone, I am new to this forum and also to the world of microcontrollers, I need a suggestion on a project that I started to develop: a small sequencer that uses the audio library to play some samples in conjunction with a TFT display to show some graphics.
I am trying to understand what is the right approach, so far I tried to set up an IntervalTimer that will be my clock, which will check the state of a pattern and in case it will play the samples from an sd card. In the meantime the screen should show some knob values.
this is my timer function
This works fine, but I don't know if it is the right method.
Anyway, when in my loop I also try to call a function to draw the tft, everything freeze:
I'd like to know what I am doing wrong, what I should consider and/or reconsider from a design perspective.
The screen works perfectly when I don't initialise the timer, and vice versa.
As I will also integrate other functions (recording steps, reading sensor, etc..) I'd like to know what is the proper way to approach this design.
Thanks!
I am trying to understand what is the right approach, so far I tried to set up an IntervalTimer that will be my clock, which will check the state of a pattern and in case it will play the samples from an sd card. In the meantime the screen should show some knob values.
this is my timer function
Code:
IntervalTimer timer;
void setup() {
//various config are excluded
timer.priority(250);
timer.begin(tick, 50000);
}
volatile unsigned long patternLength = 1;
volatile unsigned long patternDivision = 16;
volatile unsigned long tickPosition = 0;
int pattern0[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
int pattern1[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
void tick() {
if(pattern0[tickPosition]==1){
playSdWav1.play("KICK.WAV");
}
if(pattern1[tickPosition]==1){
playSdWav1.play("SNARE.WAV");
}
tickPosition ++;
if(tickPosition == patternLength * patternDivision){
tickPosition=0;
}
}
This works fine, but I don't know if it is the right method.
Anyway, when in my loop I also try to call a function to draw the tft, everything freeze:
Code:
void loop() {
drawScreen();
}
//code copied from the audio tutorial
void drawScreen(){
int leftNumber = map(analogRead(A3),0,1023,0,240);
int rightNumber = map(analogRead(A2),0,1023,0,240);
// draw the verticle bars
int height = leftNumber ;
tft.fillRect(60, 280 - height, 40, height, ILI9341_GREEN);
tft.fillRect(60, 280 - 240, 40, 240 - height, ILI9341_BLACK);
height = rightNumber ;
tft.fillRect(140, 280 - height, 40, height, ILI9341_GREEN);
tft.fillRect(140, 280 - 240, 40, 240 - height, ILI9341_BLACK);
delayMicroseconds(300);
}
I'd like to know what I am doing wrong, what I should consider and/or reconsider from a design perspective.
The screen works perfectly when I don't initialise the timer, and vice versa.
As I will also integrate other functions (recording steps, reading sensor, etc..) I'd like to know what is the proper way to approach this design.
Thanks!