Go Down

Topic: Programming for NKC Electronics RGB LCD (Read 2027 times) previous topic - next topic

Loren

This is what I would like to accomplish: 
Code: [Select]
myGLCD.print("Title: ",LEFT,5,0,0,0);
But I would like to insert a variable like this: 
Code: [Select]
myGLCD.print(name,LEFT,5,0,0,0);

Where name is a variable.

I am using henning's libraries.

Thank you,

Loren

Quote
Where name is a variable.


Is name declared as a char array or a String?

/Henning

Loren

I'm not 100% what name is and 'm still trying to get all of the code working.

I think I came up with something. 

I declared printChar as a public class in the RGB_GLCD.h and then did this:

Code: [Select]
int stl, i;
 
  stl = strlen(name);
  for (i=0; i<stl; i++)
    myGLCD.printChar(*name++, 8 + (i*6), 5, 0, 0, 0);


This probably isn't the most efficient and I'm a noob, so any nudges in the right direction are welome.

Thanks,

Loren

If you can post your complete code, I am sure we can figure it out :)

/Henning

Loren

Here it is (part of an ipod sketch):

Code: [Select]
#include "AdvancedRemote.h"
#include "Bounce.h"
#include "RGB_GLCD.h"

GLCD myGLCD;

// This sketch needs to be adapted (change serial port config in setup())
// to be used on a non-Mega, so check the board here so people notice.
/*#if !defined(__AVR_ATmega1280__)
#error "This example is for the Mega, because it uses Serial3 for the iPod and Serial for debug messages"
#endif*/

const byte BUTTON_PIN = 9;
const unsigned long DEBOUNCE_MS = 50;

Bounce button(BUTTON_PIN, DEBOUNCE_MS);
AdvancedRemote advancedRemote;

unsigned long chosenSongIndexIntoPlaylist;

//
// our handler (aka callback) implementations;
// these are what get sent data back from the iPod
// when we make requests of it.
//

void feedbackHandler(AdvancedRemote::Feedback feedback, byte cmd)
{
  Serial.print("got feedback of 0x");
  Serial.print(feedback, HEX);
  Serial.print(" for cmd 0x");
  Serial.println(cmd, HEX);

  if (feedback != AdvancedRemote::FEEDBACK_SUCCESS)
  {
    Serial.println("Giving up as feedback wasn't SUCCESS");
    return;
  }

  switch (cmd)
  {
    case AdvancedRemote::CMD_SWITCH_TO_ITEM:
    Serial.println("(Presumably) now at the playlist zero (the main one)");
    Serial.println("Asking for song count");
    advancedRemote.getSongCountInCurrentPlaylist();
    // wait for our song count handler to get called now
    break;

    case AdvancedRemote::CMD_JUMP_TO_SONG_IN_CURRENT_PLAYLIST:
    Serial.println("Jumped to our song");
    Serial.println("Asking for title");
    advancedRemote.getTitle(chosenSongIndexIntoPlaylist);
    // wait for title handler to get called now
    break;

    case AdvancedRemote::CMD_PLAYBACK_CONTROL:
    Serial.println("playback control complete");
    break;

    case AdvancedRemote::CMD_POLLING_MODE:
    Serial.println("polling mode change complete");
    // from experimentation it starts playing automatically
    break;

  default:
    Serial.println("got feedback we didn't expect");
    break;
  }
}

void titleHandler(const char *name)
{
  myGLCD.print("Title: ",LEFT,5,0,0,0);
 
  //to accomplish this:
//lzREM myGLCD.print(name,9, 5,0,0,0);
//we try:
  int stl, i;
 
  stl = strlen(name);
  for (i=0; i<stl; i++)
    myGLCD.printChar(*name++, 8 + (i*6), 5, 0, 0, 0);

  Serial.println("Asking for artist");
  advancedRemote.getArtist(chosenSongIndexIntoPlaylist);
  // wait for artist handler to get called
}

void artistHandler(const char *name)
{
  myGLCD.print("Artist: ",LEFT,15,0,0,0);
  Serial.println(name);

  Serial.println("Asking for album");
  advancedRemote.getAlbum(chosenSongIndexIntoPlaylist);
  // wait for album handler to get called
}

void albumHandler(const char *name)
{
  Serial.print("Album: ");
  Serial.println(name);

  Serial.println("Turning on polling (which also seems to make it start playing");
  advancedRemote.setPollingMode(AdvancedRemote::POLLING_START);
  Serial.println("The button will let you do play/pause now. Reset Arduino to go back to normal mode");
}

void currentPlaylistSongCountHandler(unsigned long count)
{
  Serial.print("Current playlist song count is ");
  Serial.println(count, DEC);

  // pick any old song for test porpoises
  chosenSongIndexIntoPlaylist = count / 2;

  Serial.print("Jumping to song at index ");
  Serial.println(chosenSongIndexIntoPlaylist, DEC);
  advancedRemote.jumpToSongInCurrentPlaylist(chosenSongIndexIntoPlaylist);
}

void pollingHandler(AdvancedRemote::PollingCommand command,
                    unsigned long playlistPositionOrelapsedTimeMs)
{
    Serial.print("Poll: ");

    switch (command)
    {
    case AdvancedRemote::POLLING_TRACK_CHANGE:
        Serial.print("track change to: ");
        Serial.println(playlistPositionOrelapsedTimeMs, DEC);
        break;

    case AdvancedRemote::POLLING_ELAPSED_TIME:
        Serial.print("elapsed time: ");
        printTime(playlistPositionOrelapsedTimeMs);
        break;

    default:
        Serial.print("unknown: ");
        Serial.println(playlistPositionOrelapsedTimeMs, DEC);
        break;
    }
}

void printTime(const unsigned long ms)
{
  const unsigned long totalSecs = ms / 1000;
  const unsigned int mins = totalSecs / 60;
  const unsigned int partialSecs = totalSecs % 60;

  Serial.print(mins, DEC);
  Serial.print("m ");
  Serial.print(partialSecs, DEC);
  Serial.println("s");
}

void setup()
{
  pinMode(BUTTON_PIN, INPUT);

  // enable pull-up resistor
  digitalWrite(BUTTON_PIN, HIGH);

  Serial.begin(9600);
myGLCD.initLCD();
myGLCD.fillScr(255,255,255);
myGLCD.print("Starting", CENTER,5,255,255,255);
  // enable debugging
  // #define IPOD_SERIAL_DEBUG
  // direct library's log msgs to the default serial port
  //advancedRemote.setLogPrint(Serial);
  // direct library's debug msgs to the default serial port
  //advancedRemote.setDebugPrint(Serial);

  // lzREM use Serial3 (Mega-only) to talk to the iPod
  advancedRemote.setSerial(Serial);

  // register callback functions for the things we're going to read
  advancedRemote.setFeedbackHandler(feedbackHandler);
  advancedRemote.setTitleHandler(titleHandler);
  advancedRemote.setArtistHandler(artistHandler);
  advancedRemote.setAlbumHandler(albumHandler);
  advancedRemote.setPollingHandler(pollingHandler);
  advancedRemote.setCurrentPlaylistSongCountHandler(currentPlaylistSongCountHandler);
  myGLCD.print("Functions Registered", CENTER,15,255,255,255);

  // let the library set itself up, now we've done our configuration of it
  advancedRemote.setup();
  //myGLCD.setColor();
//advancedRemote.enable();
  // start in simple remote mode
advancedRemote.disable();
}

void loop()
{
  // service iPod serial. this is who will end up
  // calling our handler functions when responses
  // come back from the iPod
  advancedRemote.loop();
 


  // use the button as a toggle
  if (button.update() && (button.read() == LOW))
  {
    //Serial.print("button pressed");
    if (advancedRemote.isCurrentlyEnabled())
    {
      //advancedRemote.disable();
      advancedRemote.controlPlayback(AdvancedRemote::PLAYBACK_CONTROL_PLAY_PAUSE);
     
    }
    else
    {
      advancedRemote.enable();

      // start our commands - we'll do them in sequence
      // as our handlers get called. for example, this
      // one will call our Feedback handler when it's done
      advancedRemote.switchToItem(AdvancedRemote::ITEM_PLAYLIST, 0);
    }
  }
}


The OP contained a snippet from the "titleHandler" function

Work is crazy so I might not be able to respond as quickly as I'd like.

Thanks,

Loren

You have to remove const from your function header.

Code: [Select]
void titleHandler(const char *name)

This works for me:
Code: [Select]
#include <RGB_GLCD.h>

GLCD myGLCD;

void titleHandler(char *name)
{
  myGLCD.print("Title:", LEFT, 5);
  myGLCD.print(name, 40, 5);
}


void setup()
{
  myGLCD.initLCD();
  myGLCD.clrScr();
  myGLCD.setColor(255,255,255);
}

void loop()
{
  titleHandler("Testing");
 
  while (true) {};
}


/Henning

Loren

Thanks for your response

I get this after I made the changes that were suggested:

Quote
secondAdv:183: error: invalid conversion from 'void (*)(char*)' to 'void (*)(const char*)'
secondAdv:183: error: initializing argument 1 of 'void AdvancedRemote::setTitleHandler(void (*)(const char*))'


What does the error mean?

I am not sure, but I think that the setTitleHandler does not accept titleHander without the const in the declaration.

As I dont have the hardware or the other libraries you are using I am unable to help any further.

/Henning

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy