1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Arduino understanding passing data to functions

Discussion in 'Arduino' started by dr pepper, Feb 9, 2017.

  1. dr pepper

    dr pepper Well-Known Member Most Helpful Member

    Joined:
    Oct 6, 2008
    Messages:
    4,759
    Likes:
    258
    Location:
    North west UK
    I recently got a mp3 player shield, it has the vs1053 codec, similar to sparkfun's & adafruits.
    I can play mp3's from an sd card, at first I put a file on the sd as per the tutorial called track001.mp3, that worked, then I put a sd card in with a load of music on and changed the track001 to wave/800hz and it worked, the mp3 file was in a folder on the sd called wave, and within the folder the track is called 800hz.
    This is the library function to play a track copied from the .h file:

    boolean startPlayingFile(const char *trackname);

    So I tried this in my code

    musicPlayer.startPlayingFile(inData)

    Indata is a character string read in from serial, I presume this doesnt work as the original function has const char defined.

    Sparkfun also does a library for this chip, but its really complex.
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Can you not just edit the CPP file? It should work then...
     
  3. dr pepper

    dr pepper Well-Known Member Most Helpful Member

    Joined:
    Oct 6, 2008
    Messages:
    4,759
    Likes:
    258
    Location:
    North west UK
    Thats the funny thing.
    The Lib didnt like me passing it a string as in String, however when I redid the code and used a character array instead of a string it worked, I thought a string was a character array - with a null at the end.
    All this without changing the header or ++ file.
    I've just been reading sdfat docs, not something I really enjoy.

    Anway whats with the new booze bottle I thought you like single malt not that treacle.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE

    With embedded processors the Constant pointer can be cast to a ram pointer but not the reverse... So you have to change the function... With C++ you can overload the function and just copy it with a character function as the parameter... Define the new overload in the private section and you can then use both..

    The Brandy was a Christmas gift from the wife... I like most liquids.... I love rum as well..
     
  6. dr pepper

    dr pepper Well-Known Member Most Helpful Member

    Joined:
    Oct 6, 2008
    Messages:
    4,759
    Likes:
    258
    Location:
    North west UK
    Yes I get that, never had it exactly like that before.

    5 years now since I had any booze, I was never a big boozer, just packed it in.
     

Share This Page