CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

transform constant char

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
soulraven



Joined: 08 Feb 2009
Posts: 72
Location: campulung muscel

View user's profile Send private message Send e-mail Yahoo Messenger

transform constant char
PostPosted: Fri Jul 10, 2009 12:29 am     Reply with quote

hi, I need help:(

I want to make an animation with ascii.

Something like this /-|-\

You know the animation, the rotation, but I want to make a function more generally.

animation(LCD_x, LCD_Y, "/-|-\")

How to animate the strings?
I use the CCS compiler and for now I make this code
Code:
void animatie(unsigned char coloana, unsigned char rand, char *animatie[11])
{
int frame;
char top[11];
strcpy(top,animatie.c_str());
//strncpy(top,animatie,2);

for (frame=0;frame<=strlen(animatie);frame++);
{
   lcd_gotoxy(coloana,rand);
   printf(lcd_putc,"%i",frame);
//   lcd_putc(top);
   lcd_outtext(animatie[frame]);

}

But is not working, how to put the strings on the pointer or matrix, and read step by step the pointer or the matrix?
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Jul 10, 2009 2:19 am     Reply with quote

There are 2 main problems with this.

1. The use of animation like this is usually to show that somethng is happening. With your code, nothing else can run while it loops through the animation. Unless you are planning on calling this within a main loop somewhere!

2. Without a delay it would cycle through the chars too quickly for you to notice the change, and it only cycles once, again you may be planning on calling this multiple times.

Options,
1. use an interrupt routine. This is probably the way I would do it using a timer interrupt. It would give a smooth animation and you don't have to worry about timing. Just start and stop.

2. Have static or global index and when this routine is called display the char at index and then increment index with a check for the end. The problem with this is that your main loop will need to keep calling this function with a suitable delay between calls. There are lots of ways to do this without using delay!

2. e.g.
First an easy way if you are using the same chars all the time
Code:

void animatie(int x, int y)
{
  static int index = 0;
  lcd_gotoxy(x, y);

  if ((index == 0) || (index == 4))
      lcd_putc('|');
  else if ((index == 1) || (index == 5))
     lcd_putc('/');
  else if ((index == 2) || (index == 6))
      lcd_putc('-');
  else
      lcd_putc('\');
  if (++index > 7)
    index = 0;
}


or

Code:

void animate(int x, int y, char *buf)
{
  static index = 0;
  lcd_gotoxy(x, y);
  lcd_putc(buf[index]);
  if (++index > 7)
    index = 0;
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group