Go Down

Topic: Sparkfun LCD Shield (Read 750 times) previous topic - next topic

Dear All,

I made a sketch for my LCD shield ( NOKIA ) but i will scroll my text ,
Is this possible ?
To scroll the text "ArduinoPAt" from the right to the left ?

Find attached the sketch and Movie:

Code: [Select]

#include <ColorLCDShield.h>

// Enter the time below in 12-hr format
#define HOURS 10
#define MINUTES 21
#define SECONDS 00
#define AMPM 0  // enter 0 for AM, 1 for PM

#define CLOCK_RADIUS 50  // radius of clock face
#define CLOCK_CENTER 55  // If you adjust the radius, you'll probably want to adjust this
#define H_LENGTH  30  // length of hour hand
#define M_LENGTH  40  // length of minute hand
#define S_LENGTH  48  // length of second hand

#define BACKGROUND  BLACK  // room for growth, adjust the background color according to daylight
#define C_COLOR  RED  // This is the color of the clock face, and digital clock
#define H_COLOR  BLUE  // hour hand color
#define M_COLOR  GREEN  // minute hand color
#define S_COLOR  YELLOW  // second hand color

LCDShield lcd;

int hours, minutes, seconds, ampm;
int buttonPins[3] = {3, 4, 5};

void setup()
{
  /* Set up the button pins as inputs, set pull-up resistor */
  for (int i=0; i<3; i++)
  {
    pinMode(buttonPins[i], INPUT);
    digitalWrite(buttonPins[i], HIGH);
  }
 
  hours = HOURS;
  minutes = MINUTES;
  seconds = SECONDS;
  ampm = AMPM;
 
  /* Initialize the LCD, set the contrast, clear the screen */
  lcd.init(PHILLIPS);
  lcd.contrast(20);
  lcd.clear(BACKGROUND);
  testPattern();


  displayDigitalTime(hours, minutes, seconds, ampm);  // Draw the digital clock text
}

void loop()
{
  /* We'll run around checking for button presses,
     until it's been a second */
  while(millis() % 1000)
  {
    if (!digitalRead(buttonPins[2]))
      setTime();  // If S3 was pressed, go set the time
  }
 
  /* We'll get here if it's been a second. We need to increase
  seconds by 1 and then go from there */
  seconds++;
  if (seconds >= 60)
  {
    seconds = 0;  // If seconds is 60, set it back to 0
    minutes++;    // and increase minutes by 1
    if (minutes >= 60)
    {
      minutes = 0;  // If minutes is 60, set it back to 0
      hours++;      // and increase hours by 1
      if (hours == 12)
        ampm ^= 1;  // If it's 12 o'clock, flip ampm
      if (hours >= 13)
        hours = 1;  // If hours is 13, set it to 1. 12-hr clock.
    }
  }
  /* Once each second, we'll redraw the clock with new values */


  displayDigitalTime(hours, minutes, seconds, ampm);
}
/*
  setTime uses on-shield switches S1, S2, and S3 to set the time
  pressing S3 will exit the function. S1 increases hours, S2
  increases seconds.
*/
void setTime()
{
  /* Reset the clock to midnight */
  seconds = 0;
  minutes = 0;
  hours = 12;
  ampm = 0;
 
  /* Draw the clock, so we can see the new time */


  displayDigitalTime(hours, minutes, seconds, ampm);
   
  while (!digitalRead(buttonPins[2]))
    ;  // wait till they let go of S1
 
  /* We'll run around this loop until S3 is pressed again */
  while(digitalRead(buttonPins[2]))
  {
    /* If S1 is pressed, we'll update the hours */
    if (!digitalRead(buttonPins[0]))
    {
      hours++;  // Increase hours by 1
      if (hours == 12)
        ampm ^= 1;  // Flip am/pm if it's 12 o'clock
      if (hours >= 13)
        hours = 1;  // Set hours to 1 if it's 13. 12-hour clock.
       
      /* and update the clock, so we can see it */


      displayDigitalTime(hours, minutes, seconds, ampm);
    }
    if (!digitalRead(buttonPins[1]))
    {
      minutes++;  // Increase minutes by 1
      if (minutes >= 60)
        minutes = 0;  // If minutes is 60, set it back to 0
       
      /* and update the clock, so we can see it */


      displayDigitalTime(hours, minutes, seconds, ampm);
    }
  }
  /* Once S3 is pressed, we'll exit, but not until it's released */
  while(!digitalRead(buttonPins[2]))
    ;
}

/*
  displayDigitalTime() takes in values for hours, minutes, seconds
  and am/pm. It'll print the time, in digital format, on the
  bottom of the screen.
*/
void displayDigitalTime(int h, int m, int s, int ap)
{
  char timeChar[13] = {'x', 'x', 0x0A, 'x', 'x', 0x0A, 'x', 'x', ' ', ' '};
 
  /* Gotta turn the values into individual integers */
  timeChar[0] = h/10;
  timeChar[1] = h - (timeChar[0] * 10);
  timeChar[3] = m/10;
  timeChar[4] = m - (timeChar[3] * 10);
  timeChar[6] = s/10;
  timeChar[7] = s - (timeChar[6] * 10);
 
  /* once we have each integer separated, we need to turn them
     into displayable characters. Adding 0x30 does this (check an
     ASCII table. We set the colons to 0x0A initially, this will
     turn them into the proper 0x3A.*/
  for (int i=0; i<8; i++)
    timeChar[i] += 0x30;
   
  timeChar[8] = ' ';  // add a space between the time and AM/PM
 
  /* Add AM or PM to the end of the timeChar string */
  if (!ap)
  {
    timeChar[9] = 'A';
    timeChar[10] = 'M';
  }
  else
  {
    timeChar[9] = 'P';
    timeChar[10] = 'M';
  }
 
  /* add some blank spaces after the time, otherwise it'll display
     unwanted characters */
  timeChar[11] = ' ';
  timeChar[12] = ' ';
 
  /* Print the time on the clock */
  lcd.setStr(timeChar, CLOCK_CENTER + CLOCK_RADIUS + 0, 20, C_COLOR, BACKGROUND);
  lcd.setStr("ArduinoPat", 2, 20, C_COLOR, BACKGROUND);
}

void testPattern()
{

 
  lcd.setRect(0, 2, 131, 19, 1, WHITE);
  lcd.setRect(0, 19, 131, 35, 1, YELLOW);
  lcd.setRect(0, 35, 131, 51, 1, CYAN);
  lcd.setRect(0, 51, 131, 67, 1, GREEN);
  lcd.setRect(0, 67, 131, 83, 1, MAGENTA);
  lcd.setRect(0, 83, 131, 99, 1, RED);
  lcd.setRect(0, 99, 131, 115, 1, BLUE);
  lcd.setRect(0, 115, 131, 131, 1, BLACK);
}





http://www.youtube.com/watch?v=OYAIAoAjybI

Thsanks for read this post,

Regards,

ArduinoPat , The Netherlands

Patrick ,The Netherlands

guix

#1
Oct 21, 2012, 07:15 pm Last Edit: Oct 21, 2012, 07:29 pm by guix Reason: 1
Hello :),

I think you can do something like that:
Code: [Select]

unsigned long now = 0;
unsigned long time = 0;
int x = 320; //or whatever is the size of your screen in pixel
int textSize = 150; //or whatever, you have to test for the correct value, or maybe you have a function getTextSize?

void loop()
{
 now = millis();
 if ( now - time >= 10 ) // 10 milliseconds has passed
 {
   time = now;
   lcd.setStr("ArduinoPat", x, 20, C_COLOR, BACKGROUND);
   x--;
   if (x < -textSize) //if the text is out of the screen, reset x so the message appear again from the right
     x = 320;
 }
}

Dear Guix,

Sorry for late reply , :smiley-roll:

Many thank's for this sketch , but it's not the way what i mean.
But any way is it possible for only scroll the text ?
No the text scroll together with a black background , is it possible without black background and only text in the testpattern ?

Code: [Select]

#include <ColorLCDShield.h>

// Enter the time below in 12-hr format
#define HOURS 10
#define MINUTES 21
#define SECONDS 00
#define AMPM 0  // enter 0 for AM, 1 for PM

#define CLOCK_RADIUS 50  // radius of clock face
#define CLOCK_CENTER 55  // If you adjust the radius, you'll probably want to adjust this
#define H_LENGTH  30  // length of hour hand
#define M_LENGTH  40  // length of minute hand
#define S_LENGTH  48  // length of second hand

#define BACKGROUND  BLACK  // room for growth, adjust the background color according to daylight
#define C_COLOR  RED  // This is the color of the clock face, and digital clock
#define H_COLOR  BLUE  // hour hand color
#define M_COLOR  GREEN  // minute hand color
#define S_COLOR  YELLOW  // second hand color

LCDShield lcd;

int hours, minutes, seconds, ampm;
int buttonPins[3] = {3, 4, 5};

unsigned long now = 0;
unsigned long time = 0;
int x = 320; //or whatever is the size of your screen in pixel
int textSize = 150; //or whatever, you have to test for the correct value, or maybe you have a function getTextSize?



void setup()
{
  /* Set up the button pins as inputs, set pull-up resistor */
  for (int i=0; i<3; i++)
  {
    pinMode(buttonPins[i], INPUT);
    digitalWrite(buttonPins[i], HIGH);
  }
 
  hours = HOURS;
  minutes = MINUTES;
  seconds = SECONDS;
  ampm = AMPM;
 
  /* Initialize the LCD, set the contrast, clear the screen */
  lcd.init(PHILLIPS);
  lcd.contrast(20);
  lcd.clear(BACKGROUND);
  testPattern();


  displayDigitalTime(hours, minutes, seconds, ampm);  // Draw the digital clock text
}

void loop()
{
  /* We'll run around checking for button presses,
     until it's been a second */
  while(millis() % 1000)
  {
    if (!digitalRead(buttonPins[2]))
      setTime();  // If S3 was pressed, go set the time
  }
 
  {
  now = millis();
  if ( now - time >= 10 ) // 10 milliseconds has passed
  {
    time = now;
    lcd.setStr("ArduinoPat", x, 20, C_COLOR, BACKGROUND);
    x--;
    if (x < -textSize) //if the text is out of the screen, reset x so the message appear again from the right
      x = 320;
  }
}
 
  /* We'll get here if it's been a second. We need to increase
  seconds by 1 and then go from there */
  seconds++;
  if (seconds >= 60)
  {
    seconds = 0;  // If seconds is 60, set it back to 0
    minutes++;    // and increase minutes by 1
    if (minutes >= 60)
    {
      minutes = 0;  // If minutes is 60, set it back to 0
      hours++;      // and increase hours by 1
      if (hours == 12)
        ampm ^= 1;  // If it's 12 o'clock, flip ampm
      if (hours >= 13)
        hours = 1;  // If hours is 13, set it to 1. 12-hr clock.
    }
  }
  /* Once each second, we'll redraw the clock with new values */


  displayDigitalTime(hours, minutes, seconds, ampm);
}
/*
  setTime uses on-shield switches S1, S2, and S3 to set the time
  pressing S3 will exit the function. S1 increases hours, S2
  increases seconds.
*/
void setTime()
{
  /* Reset the clock to midnight */
  seconds = 0;
  minutes = 0;
  hours = 12;
  ampm = 0;
 
  /* Draw the clock, so we can see the new time */


  displayDigitalTime(hours, minutes, seconds, ampm);
   
  while (!digitalRead(buttonPins[2]))
    ;  // wait till they let go of S1
 
  /* We'll run around this loop until S3 is pressed again */
  while(digitalRead(buttonPins[2]))
  {
    /* If S1 is pressed, we'll update the hours */
    if (!digitalRead(buttonPins[0]))
    {
      hours++;  // Increase hours by 1
      if (hours == 12)
        ampm ^= 1;  // Flip am/pm if it's 12 o'clock
      if (hours >= 13)
        hours = 1;  // Set hours to 1 if it's 13. 12-hour clock.
       
      /* and update the clock, so we can see it */


      displayDigitalTime(hours, minutes, seconds, ampm);
    }
    if (!digitalRead(buttonPins[1]))
    {
      minutes++;  // Increase minutes by 1
      if (minutes >= 60)
        minutes = 0;  // If minutes is 60, set it back to 0
       
      /* and update the clock, so we can see it */


      displayDigitalTime(hours, minutes, seconds, ampm);
    }
  }
  /* Once S3 is pressed, we'll exit, but not until it's released */
  while(!digitalRead(buttonPins[2]))
    ;
}

/*
  displayDigitalTime() takes in values for hours, minutes, seconds
  and am/pm. It'll print the time, in digital format, on the
  bottom of the screen.
*/
void displayDigitalTime(int h, int m, int s, int ap)
{
  char timeChar[13] = {'x', 'x', 0x0A, 'x', 'x', 0x0A, 'x', 'x', ' ', ' '};
 
  /* Gotta turn the values into individual integers */
  timeChar[0] = h/10;
  timeChar[1] = h - (timeChar[0] * 10);
  timeChar[3] = m/10;
  timeChar[4] = m - (timeChar[3] * 10);
  timeChar[6] = s/10;
  timeChar[7] = s - (timeChar[6] * 10);
 
  /* once we have each integer separated, we need to turn them
     into displayable characters. Adding 0x30 does this (check an
     ASCII table. We set the colons to 0x0A initially, this will
     turn them into the proper 0x3A.*/
  for (int i=0; i<8; i++)
    timeChar[i] += 0x30;
   
  timeChar[8] = ' ';  // add a space between the time and AM/PM
 
  /* Add AM or PM to the end of the timeChar string */
  if (!ap)
  {
    timeChar[9] = 'A';
    timeChar[10] = 'M';
  }
  else
  {
    timeChar[9] = 'P';
    timeChar[10] = 'M';
  }
 
  /* add some blank spaces after the time, otherwise it'll display
     unwanted characters */
  timeChar[11] = ' ';
  timeChar[12] = ' ';
 
  /* Print the time on the clock */
  lcd.setStr(timeChar, CLOCK_CENTER + CLOCK_RADIUS + 0, 20, C_COLOR, BACKGROUND);
  lcd.setStr("ArduinoPat", 2, 20, C_COLOR, BACKGROUND);
}

void testPattern()
{

 
  lcd.setRect(0, 2, 131, 19, 1, WHITE);
  lcd.setRect(0, 19, 131, 35, 1, YELLOW);
  lcd.setRect(0, 35, 131, 51, 1, CYAN);
  lcd.setRect(0, 51, 131, 67, 1, GREEN);
  lcd.setRect(0, 67, 131, 83, 1, MAGENTA);
  lcd.setRect(0, 83, 131, 99, 1, RED);
  lcd.setRect(0, 99, 131, 115, 1, BLUE);
  lcd.setRect(0, 115, 131, 131, 1, BLACK);
}





http://www.youtube.com/watch?v=FcDi0EqZ55Y&feature=vmdshb


Thanks for reply !!!

Regards,

ArduinoPat, Patrick , The Netherlands

Patrick ,The Netherlands

guix

#3
Oct 26, 2012, 06:12 pm Last Edit: Oct 26, 2012, 06:16 pm by guix Reason: 1
Hello ArduinoPAT,

Sorry I don't have this lcd display so I can't test...but I think I understand what you want: scroll text only inside the blackbox, not the whole display.

There is an easy way, but not perfect, it scroll one character instead of one pixel. Look this code, I hope it will help you :)

http://codepad.org/W2F0YNpw

Dear Guix,

Many thanks for you input, but i am searching for another sketch.
I will investigate what sketch will scroll the text without background.

i appraciate you time and input for this  :)

When i have the solution i will post it at the forum , for everybody who is interested in this

Best Regards ,

Patrick ,ArduinoPat , The Netherlands.
Patrick ,The Netherlands

Go Up