Show Posts
Pages: 1 ... 8 9 [10]
136  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
137  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
138  Using Arduino / Displays / Programming for NKC Electronics RGB LCD on: February 17, 2011, 01:19:02 pm
This is what I would like to accomplish: 
Code:
myGLCD.print("Title: ",LEFT,5,0,0,0);
But I would like to insert a variable like this: 
Code:
myGLCD.print(name,LEFT,5,0,0,0);

Where name is a variable.

I am using henning's libraries.

Thank you,

Loren
139  Forum 2005-2010 (read only) / Development / Re: New library: RGB GLCD (LDS183 Controller) on: January 14, 2011, 03:27:29 pm
Quote
I'll look into the problem, but it might take a couple of days...

/Hennning

Thank you very much...Take your time!
140  Forum 2005-2010 (read only) / Development / Re: New library: RGB GLCD (LDS183 Controller) on: January 14, 2011, 08:03:04 am
Thanks For your help!

Here are a couple pictures:






And here is the code:

Code:
// RGB_GLCD_Bitmap (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the drawBitmap()-function.
//

#include "RGB_GLCD.h"
#include <avr/pgmspace.h>

GLCD myGLCD;

extern unsigned int icon1[0x400];
extern unsigned int icon2[0x400];
extern unsigned int tux[0x1000];

void setup()
{
  myGLCD.initLCD();
  //myGLCD.clrScr();
        myGLCD.fillScr(255,255,255);
  //myGLCD.setColor(255,255,255);
  myGLCD.print("Hello World Init",CENTER,5,255,255,255);
 
 
  // Draw a moving sinewave
  
   byte buf[126];
  int x, x2;
  int y, y2;
  int r;
  x=1;
  for (int i=1; i<3654; i++)
  {
    x++;
    if (x==127)
      x=1;
    if (i>127)
    {
      if ((x==63)||(buf[x-1]==63))
        myGLCD.setColor(0,0,255);
      else
        myGLCD.setColor(255,255,255);
      myGLCD.drawPixel(x,buf[x-1]);
    }
    myGLCD.setColor(0,255,255);
    y=63+(sin(((i*1.3)*3.14)/180)*50);
    myGLCD.drawPixel(x,y);
    buf[x-1]=y;
//    delay(3);
  }
  delay(5000);
  myGLCD.clrScr();
  myGLCD.fillScr(255,255,255);
}

void loop()
{
myGLCD.setColor(0,0,0);
  myGLCD.print("Blinking Message", CENTER,5,255,255,255);
    myGLCD.print("Line 2 stuff", CENTER,15,255,255,255);
  
 delay(1000);
 myGLCD.setColor(255,255,255);
 myGLCD.print("Blinking Message", CENTER,5,0,0,0);
 myGLCD.setColor(0,0,0);
 myGLCD.print("Line 2 stuff", CENTER,15,255,255,255);
 delay(1000);
  myGLCD.setColor(0,0,0);
 myGLCD.print("Blinking Message", CENTER,5,255,255,255);
 myGLCD.setColor(255,255,255);
 myGLCD.print("Line 2 stuff", CENTER,15,0,0,0);
 delay(1000);
 
}

I have downloaded the graph code and will try and figure out the Large Font stuff.  

Thank you again for your help.

Loren
141  Forum 2005-2010 (read only) / Development / Re: New library: RGB GLCD (LDS183 Controller) on: January 13, 2011, 09:45:01 pm
I just got an arduino (My first one so bear with me as I am new to this) and the LDS183.  With your code I've gotten it going with very little trouble.  Thank you for that!

I do have a couple of questions though

First when I display white text on a black background there appears to be white vertical lines  through the text 1 pixel wide (like the pipe charecter "|") at a couple of places making the text harder to read.  Is there a way to eliminate those lines?

Second, is there a way to make the text bigger?  If I need to I'm happy to do some reading or coding.  I just don't have a clue where to look.

Thanks again,

Loren
142  Forum 2005-2010 (read only) / Development / Guitar pedal to control iPod on: January 17, 2011, 11:00:46 am
Hello everybody,

As a favor for a friend of mine I'm building a guitar pedal that will control his iPod (he uses it for loops while playing).  I've seen a couple of iPod accessories driven by Arduino, but my question is does anyone know if iPods need 3v or 5v for the serial communications (I've seen project examples using both)?  If it needs 3 I would hate to fry his iPod.  If it needs 5 I would hate to have a unreliable device.

Thank you!

Loren  
Pages: 1 ... 8 9 [10]