Show Posts
Pages: 1 ... 8 9 [10] 11
136  Using Arduino / Programming Questions / Re: int to char question on: March 14, 2012, 07:45:22 am
Sorry I was in the middle of four things....  for a moment it was only displaying a zero. 

I had some other code botched.  Now it is working as it should.  Thanks for all of the help.
137  Using Arduino / Programming Questions / Re: int to char question on: March 14, 2012, 07:35:04 am
 
Then, no, you are not using sprintf() correctly.

The way you have c defined, it is a pointer. What does it point to? Nothing. And, yet, you as sprintf() to write to the memory pointed to by c.
Code:
char c[4];
sprintf(c, "%d", red);
would work.

It does work...but only partially
138  Using Arduino / Programming Questions / Re: int to char question on: March 14, 2012, 06:55:16 am
sorry here it is:

Code:
int red = 255;
char *c;
sprintf(c, "%d", red);
139  Using Arduino / Programming Questions / Re: int to char question on: March 14, 2012, 06:49:20 am
Thanks guys,

Here is what I've tried without any luck:

Code:
int red = 255;
sprintf(c, "%d", red);
Do I understand sprintf correctly?
140  Using Arduino / Programming Questions / int to char question on: March 13, 2012, 08:46:05 pm
I would like to display some information on NKC display

this code does what you would think:

Code:
myGLCD.print("blue:", LEFT, 70,255,255,255);

I've googled to try and figure this question out but have not been successful.

I have several int variables that I need to display.  This just displays garbage:
Code:
int chnlD = 1;
 char *c;
 c=(char *)chnlD;

Any suggestions would be great!
Thanks for checking in,
Loren
141  Using Arduino / Programming Questions / reading incomming serial information while loop is running on: March 10, 2012, 11:39:38 am
Hi,

I have a loop that runs to show text on a display.  I would like to send information to the arduino on the serial buss.  Does anyone have a suggestion how I could get that information to the display? 

My initial thought is that there has to be a way to update a variable somehow with the information coming down the serial buss.  Am I close?

Loren
142  Using Arduino / Programming Questions / Re: iPodSerial Questions on: February 22, 2011, 09:23:45 pm
No need to apologize, I'm just grateful for your help.  I got it to compile.  Now I just need a TTL to serial adapter and I should be set to get going.

Thanks again,

Loren
143  Using Arduino / Programming Questions / Re: iPodSerial Questions on: February 22, 2011, 07:34:27 pm
Sorry to be such a pain but I think I have misunderstood somewhere.

Quote
// enable debugging (this #define should go at the top of the file)
#define IPOD_SERIAL_DEBUG
This goes in iPodSerial.h Right?

Quote
// (create your NewSoftwareSerial)
This also goes in iPodSerial.h Right?

If I have it in the right places then something is weird because I'm getting multiple definition errors.

Any thoughts?

Thanks again,

Loren
144  Using Arduino / Programming Questions / Re: iPodSerial Questions on: February 22, 2011, 04:59:19 pm
Cool,

Thanks to you both for clearing both of those issues up.  I think I now have the info that I need to continue on!

Loren
145  Using Arduino / Programming Questions / Re: iPodSerial Questions on: February 22, 2011, 04:23:31 pm
I started to attempt to use NewSoftSerial for interfacing with the iPod.  I have inserted this:

Code:
#include "iPodSerial.h"
#include "NewSoftSerial.h"
#include <ctype.h>

#define rxPin 6
#define txPin 7
NewSoftSerial nss(rxPin, txPin);


static const char *STATE_NAME[] =
{
    "Waiting for Header 1",
    "Waiting for Header 2",
    "Waiting for length",
    "Waiting for data",
    "Waiting for checksum"
};

iPodSerial::iPodSerial(): receiveState(WAITING_FOR_HEADER1),
dataSize(0),
pData(0),
checksum(0),
pSerial(nss)
#if defined(IPOD_SERIAL_DEBUG)
,
pDebugPrint(0), // default to no debug, since most Arduinos don't have a spare serial to use for debug
pLogPrint(0) // default to no log, since most Arduinos don't have a spare serial to use for debug
#endif
{
}

A couple of things puzzle me first if I use #include <NewSoftSerial.h> I get a file not found error.  Can someone explain what the difference between " " and <> for including files.

Second if I use #include "NewSoftSerial.h" I get this error:

Quote
error: cannot convert 'NewSoftSerial' to 'HardwareSerial*' in initialization

Does anyone have any insight?

Thank you very much,

Loren
146  Using Arduino / Programming Questions / Re: iPodSerial Questions on: February 21, 2011, 07:32:51 pm
A logic converter connects the iPod to pins 0 & 1.

Would it be better to use something else (like a serial LCD)to debug instead of a bunch of reprogramming?
147  Using Arduino / Programming Questions / iPodSerial Questions on: February 21, 2011, 12:26:24 pm
Hi,

I'm working on a IpodSerial project.  I'm using an Uno and would like to use the serial monitor to debug.  Which leads me to the fact that I need to communicate with my iPod on pins other than 0 & 1.  Could I use Software Serial for this?  If so would the definition for the port go in the iPodSerial.cpp here:

Code:
iPodSerial::iPodSerial()
: receiveState(WAITING_FOR_HEADER1),
dataSize(0),
pData(0),
checksum(0),
pSerial(&Serial) // default to regular serial port as that's all most Arduinos have
#if defined(IPOD_SERIAL_DEBUG)
,
pDebugPrint(0), // default to no debug, since most Arduinos don't have a spare serial to use for debug
pLogPrint(0) // default to no log, since most Arduinos don't have a spare serial to use for debug
#endif
{
}

Thanks,

Loren
148  Using Arduino / Displays / Re: Programming for NKC Electronics RGB LCD on: February 21, 2011, 10:45:03 am
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?
149  Using Arduino / Displays / Re: Programming for NKC Electronics RGB LCD on: February 19, 2011, 07:16:54 am
Here it is (part of an ipod sketch):

Code:
#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
150  Using Arduino / Displays / Re: Programming for NKC Electronics RGB LCD on: February 17, 2011, 07:51:54 pm
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:
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
Pages: 1 ... 8 9 [10] 11