Go Down

Topic: MIDI library conflict? (Read 4 times) previous topic - next topic

marco_c

Breaks what? Your code does not seem to do anything as you have posted it.

Do you have enough RAM?
Arduino libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

deseipel

Sorry I wasn't clear.  I may have found the issue.  If the SD card can't initialize, it's my understanding that the SPI speed can be affected, which may explain.  First, I must see why my card won't initialize.

deseipel

ok, I took the card out and unplugged the arduino and that worked; the card doesn't fail to initialize now.

But, here's the code that doesn't work (screen flashes black, then white).  It should show my menu.

Code: [Select]



#include <Adafruit_ST7735.h>
#include <Adafruit_GFX.h>
#include <SoftwareSerial.h>
#include <SdFatUtil.h>
#include <SdFat.h>
#include <SPI.h>
#include <MIDIFile.h>
#include <MIDIHelper.h>



/// Edit for Shield Pinouts!
#define SD_CS    4  // Chip select line for SD card
#define TFT_CS  10  // Chip select line for TFT display
#define TFT_DC   8  // Data/command line for TFT
#define TFT_RST  0  // Reset line for TFT (or connect to +5V)
#define ADA_JOYSTICK 3
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
MIDIFile SMF;  // or this breaks it.  POSSIBLY A CONFLICT WITH SERIAL ?  TFT?
SdFat SD;




Code: [Select]
////////////////////////////////////////////////////////////////////////////////
bool doMenu( void ){
//uint8_t b = checkJoystick();

uint8_t b = CheckJoystick();
if( b == Neutral ){
return false;   //  user input didn't happen
}

//  enable menu if up, else ignore input & return  ---------------------------------------
if( ! menu_enable ) {
if( b == Up ) {
menu_enable = 1;
curr_selection = 0;   //  start with top item as selected
cls();
draw_menu();
}
return 0;
}

//-----------------------------------------------------------------------------------------
SELECTION *selptr = &curr_menu->selection[ curr_selection ];
tft.setCursor(0,10);
// const char* Buttons[]={"Neutral", "Press", "Up", "Down", "Right", "Left" };
if( b == Up ) {
if(curr_selection > 0)
curr_selection--;
else    //  wrap around
    curr_selection = curr_menu->num_selections-1;
} else if( b == Down ) {
if(curr_selection < curr_menu->num_selections-1 )
curr_selection++;
else
    curr_selection=0;
} else if( b == Left ) {    //  back out to higher menu
menu_parent();
} else if( b == Right || b == Press ) {
// curr_menu->selection[curr_selection].function();
selptr->function( selptr->fn_arg );
}
if( b == Up || b == Down )
    draw_menu( );
return true;    //  user input happened
}
////////////////////////////////////////////////////////////////////////////////
//  Finds parent of current menu and resets curr_menu to it and draws menu
void menu_parent( ){
    curr_selection=0;
//  already at top of menu, so hide it. &menu[0] used as is more obvious than just 'menu'
if( curr_menu == &menu[0] && menu_enable ) {
    menu_enable = false;
} else {
//  a_menu is working copy of curr_menu, which will get reset to our parent
MENU *a_menu = curr_menu;
// Create a selection pointer for convenience
//  the LAST selection in a menu must be to "go up" a menu
static int num_menus=sizeof(_menus);
SELECTION *selptr = &a_menu->selection[ a_menu->num_selections - 1 ];
for( int menuidx = 0; menuidx < num_menus ; menuidx++ ) {
    if( selptr->fn_arg == menu[menuidx].id ) {
        curr_menu=&menu[menuidx];
        curr_selection=0;
        break;
        }
    }
}
cls();
draw_menu();
}
////////////////////////////////////////////////////////////////////////////////
//  displays the currently selected menu (or uarr for menu if not enabled)
void draw_menu( ){
if( ! menu_enable ) {
cls();
sprintf( text, "%c for menu", uarr );
tft.print( text );
//guiFooter();
return;
}
//uint16_t colorsave = tft.getTextColor();
tft.setTextColor( menu_color );
tft.setCursor(0, 2);
//  magic number alert! set %-20.20s to same value as MAX_PROMPT_LEN
sprintf( text, "%-20.20s\n", curr_menu->label );
tft.print(text);
int selection_num = 0;
// Loop through the actual number of selections in THIS menu
for(selection_num=0; selection_num < curr_menu->num_selections; selection_num++)
{
// Create a pointer for convenience
SELECTION *selptr = &curr_menu->selection[selection_num];
// If this is the "active" menu selection (determine by referencing the global
// variable 'curr_selection' then draw it in inverse text.
if (selection_num == curr_selection)
    tft.setTextColor(BLUE);
// Print the prompt string
//tft.setCursor(selection_num + MENU_INDENT_Y, MENU_INDENT_X);
sprintf( text, "  %-20.20s\n", selptr->label );
tft.print(text);
// Turn inverse back off if need be
if (selection_num == curr_selection)
    tft.setTextColor(RED);
}

tft.setTextColor( WHITE );

}
////////////////////////////////////////////////////////////////////////////////
void setup(){
  tft.initR( INITR_BLACKTAB );    //  "tab color" from screen protector; there's RED and GREEN, too.

//tft.setTextColor(RED);
tft.fillScreen(BLACK);
tft.setTextSize(1); //  1 = 5x8, 2 = 10x16; chars leave blank pixel on bottom
tft.println("TFT Setup Completed");
//delay(500);
// cls();
//Serial.begin(9600);
// SMF.begin(&SD);
//if (!SD.begin(SD_CS, SPI_HALF_SPEED)) SD.initErrorHalt();
  if (!SD.begin(SD_CS, SPI_HALF_SPEED))
{
//     //   Serial.print("\nSD init fail!");
   tft.println("SD init fail!");
  return;
}
//Serial.println("draw_menu");
draw_menu();
//Serial.println("Setup completed");
//delay(500);
//cls();
}

////////////////////////////////////////////////////////////////////////////////
//  clearscreen helper for tft
void cls() {
tft.fillScreen(BLACK);
tft.setCursor(0, 2);
}



////////////////////////////////////////////////////////////////////////////////
void loop() {

if( doMenu() ){

 
//  something happened with joystick, an update() action could be called here
}

}



basically all I've done is add MIDIFile SMF;   

the setup setups the TFT, the SD card and then draws the menu and the loop calls doMenu().  When I comment out MIDIFile SMF;  the menu works.  When I comment out draw_menu(); the screen is just black (as expected).  the question is, how is the menu code conflicting with the MIDIFile SMF declaration?


marco_c

Back to the original question. Do you have enough RAM to run all this?
Arduino libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

deseipel

the sketch is only 19k.   

I'll run a memory checker

Let's assume I do.

deseipel

I'm going to pick up a Mega to see if that helps.

marco_c

Quote
the sketch is only 19k.


This is not relevant to the amount of RAM. On an UNO, the RAM is 2k. The RAM holds all the variables, objects, data, etc (basically the stack and the heap memory). If your libraries need more than or even close to 2k then you are likely to have problems.
Arduino libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

deseipel

Thanks, I wasnt sure.

Well, I can report that after picking up a Mega, the code works again. Thanks for your time.

Go Up