NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » .....help meeeeeeee.....

June 11, 2010
by Master_Programmer
Master_Programmer's Avatar

okay, i'm making an RPG for a game system i made out of the nerd kits.......the problem is, i don't know how to display a string of text from an array, to the LCD screen..... :(

June 11, 2010
by Master_Programmer
Master_Programmer's Avatar

i tried this code: char ENEMY[4][10]={{"CROW"},{"GUY"},{"GUY"},{"GUY"}}; lcd_write_string(ENEMY[1]);

but that just makes a TON of garbled text appear..... :(

June 11, 2010
by wayward
wayward's Avatar

Hi Master_Programmer,

check this thread out: http://www.nerdkits.com/forum/thread/100/

By the way, everyone, has this explanation been superseded by another thread? I'm not really visiting all that regularly.

June 15, 2010
by Master_Programmer
Master_Programmer's Avatar

okay, i got the strings to work by "cheating" a bit, but for some reason, when i use a 2d array, when i go to display the values to the LCD, depending on the int type i used, it either displays "255" or "-1" all the time....and i've been searching around on google, but can't seem to find the answer.... here's the code i'm using:

    uint8_t ENEMYST[6][4]={{10,3,0,4},{16,5,3,7},{22,7,4,13},{29,12,1,19},{38,15,7,13},{120,21,9,19}};
    lcd_write_string(PSTR("H:"));
    lcd_write_int16(ENEMYST[r][0]);
    lcd_write_string(PSTR(" O:"));
    lcd_write_int16(ENEMYST[r][1]);
June 15, 2010
by Master_Programmer
Master_Programmer's Avatar

nevermind....i think i found the answer......i think the random number i'm rolling, is using decimal places, which is screwing up my readings.....

June 15, 2010
by Master_Programmer
Master_Programmer's Avatar
 r = level;

 EHP = ENEMYST[r][0];

  N = r;

  lcd_line_one();
  lcd_write_string(PSTR("        DEBUG       "));
  lcd_line_two();
  NAMER(N);

  lcd_line_three();
  lcd_write_string(PSTR("H:"));
  lcd_write_int16(EHP);
  lcd_write_string(PSTR(" O:"));
  lcd_write_int16(ENEMYST[r][1]);
  lcd_write_string(PSTR(" D:"));
  lcd_write_int16(ENEMYST[r][2]);
  lcd_write_string(PSTR(" E:"));
  lcd_write_int16(ENEMYST[r][3]);
  lcd_line_four();
  lcd_write_string(PSTR("Enemy:"));
  lcd_write_int16(r);
  lcd_write_string(PSTR(" en1hp:"));
  lcd_write_int16(ENEMYST[1][0]);

okay, this is giving me troubles.....whenever i change the "level" value even just a TINY bit, they game displays 255's for ALL THE VALUES.

June 15, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Master_Programmer,

It's really hard to tell what the problem might be from that snippet of code. How big is the ENEMYST array, could you be running out of RAM perhaps? Could the r index be out of bounds in the array?

I can't see anything that might be causing that problem in that piece of code, perhaps if post more of what is going on someone can spot the issue.

Humberto

June 15, 2010
by Master_Programmer
Master_Programmer's Avatar

here's the entire program:

#define F_CPU 14745600

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#

#include <avr/io.h>

#include <avr/interrupt.h>

#include <avr/pgmspace.h>

#include <inttypes.h>

#include "../libnerdkits/delay.h"

#include "../libnerdkits/lcd.h"

#include "../libnerdkits/uart.h"

// PIN DEFINITIONS:

//

// PC1 -- DIP SWITCH DP1

// PC2 -- DIP SWITCH DP2

// PC2 -- DIP SWITCH DP3

// PC3 -- DIP SWITCH DP4

// PC4 -- DIP SWITCH DP5

// PC5 -- DIP SWITCH DP6

//

// NOTE: (switches connects to GND when closed, otherwise

 // the pin is internally pulled up through a pull-up resistor to VCC)

int main() {

  // start up the LCD

  lcd_init();

  lcd_home();

  // Set the 6 pins to input mode - Two 3 bit numbers

  DDRC &= ~(1<<PC0); // set Pa1 as input

  DDRC &= ~(1<<PC1); // set Pa2 as input

  DDRC &= ~(1<<PC2); // set Pa2 as input

   // turn on the internal resistors for the pins

  PORTC |= (1<<PC0); // turn on internal pull up resistor for Pa1

  PORTC |= (1<<PC1); // turn on internal pull up resistor for Pa2

  PORTC |= (1<<PC2); // turn on internal pull up resistor for Pa2

   // declare the variables to represent each bit, of our two 3 bit numbers

  uint8_t a1 = 1;

  uint8_t a2 = 1;

  uint8_t a3 = 1;

  uint8_t sr = 0;

  uint8_t t = 0, EHP = 0, N = 0,r, mhp = 20, hp = mhp, ofs = 5, dfs = 2, mx = 10, ex = 0, level = 2, dead = 0;

  uint8_t ENEMYST[6][4]={{10,3,0,4},{16,5,3,7},{22,7,4,13},{29,12,1,19},{38,15,7,13},{120,21,9,19}};

  lcd_clear_and_home();

while(1) {

  lcd_clear_and_home();

      // (PINC & (1<<PC0)) returns 8 bit number, 0's except position Pa1 which is

      // the bit we want

      // shift it back by Pa1 to put the bit we want in the 0th position.

  lcd_line_one();

  lcd_write_string(PSTR("      EARTHBOUND    "));

  lcd_line_two();

  lcd_write_string(PSTR("   GIYGAS' RETURN   "));

  lcd_line_three();

  lcd_write_string(PSTR("                    "));

  lcd_line_four();

  lcd_write_string(PSTR("PAULSOFT -  0/0/0000"));

   while(a1 == 1) {

  a1 = (PINC & (1<<PC0)) >> PC0;

   }

 while(dead == 0) {

  delay_ms(1000);

     lcd_clear_and_home();

       a1 = 1;

   a2 = 1;

   a3 = 1;

       sr = sr + 1;

  srand((unsigned) sr);

   t = rand()%100;

   t = 61;

  if(t >= 61) {

 r = level;

  EHP = ENEMYST[r][0];

  N = r;

  lcd_line_one();

  lcd_write_string(PSTR("        DEBUG       "));

  lcd_line_two();

  NAMER(N);

  lcd_line_three();
  lcd_write_string(PSTR("H:"));

  lcd_write_int16(EHP);

  lcd_write_string(PSTR(" O:"));

  lcd_write_int16(ENEMYST[r][1]);

  lcd_write_string(PSTR(" D:"));

  lcd_write_int16(ENEMYST[r][2]);

  lcd_write_string(PSTR(" E:"));

  lcd_write_int16(ENEMYST[r][3]);

  lcd_line_four();

  lcd_write_string(PSTR("Enemy:"));

  lcd_write_int16(r);

  lcd_write_string(PSTR(" en1hp:"));

  lcd_write_int16(ENEMYST[1][0]);

  while(a1 == 1) {

  a1 = (PINC & (1<<PC0)) >> PC0;

 }

           }
              }

 }

 return 0;

}

int NAMER(int namenum) {

if(namenum == 0) {

  lcd_write_string(PSTR("Crow"));

  }

if(namenum == 1) {

  lcd_write_string(PSTR("Batty"));

  }

if(namenum == 2) {

  lcd_write_string(PSTR("Zombie"));

  }

if(namenum == 3) {

  lcd_write_string(PSTR("St.Man"));

  }

if(namenum == 4) {

  lcd_write_string(PSTR("Ev.Bot"));

  }

if(namenum == 5) {

  lcd_write_string(PSTR("St.Man+"));

  }

if(namenum == 6) {

  lcd_write_string(PSTR("GIYGAS"));

  }

return namenum;

}
June 16, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Master_Programmer,

I tried your program on my NerdKit here, it seems to work correctly with level set to 2,4 and 5. I get the proper values coming from the array. Can you describe more precisely what set of variables are causing the problem?

Humberto

p.s. I look forward to playing Giygas Return!

June 17, 2010
by Master_Programmer
Master_Programmer's Avatar

when ever i use levels 0 and 1, it displays either a "-1" or a "255", depending on the type of integer i set it to......maybe i should try to make a workaround again....... XD i'm a veteran basic programmer, so i'm pretty good at finding ways around things. XD

June 17, 2010
by Master_Programmer
Master_Programmer's Avatar

i just realized something, it only screws up when i change the level, but only if i change it after i have already initialized it.

June 17, 2010
by Master_Programmer
Master_Programmer's Avatar

also, it only screws up if i change anything related to the value used to determine the enemy, or i should say, value 'r'

June 17, 2010
by Master_Programmer
Master_Programmer's Avatar

oh wait......nevermind. i just realized, the answer to this problem. i don't actually need to display the values.......that was just to see if the arrays were working right...... XD so anyways, the new earthbound game i'm making is back on track, and should be finished within a week. :D and hevans, because you were the first person looking forward to it, imma send you the first finished copy i make. XD

June 17, 2010
by Master_Programmer
Master_Programmer's Avatar

okaaaaaaaay......every time i use the 'r' to tell which enemy you're fighting, if i even put a STATEMENT that will change the value of 'level', 'r' screws up completely.

June 18, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Master_Programmer,

The only thing I see different with r, and the rest of your variables is that you don't initialize r when you declare it. It should not make a difference, but depending on when you use r, it might.

Could you post the set of circumstances that cause the error to happen. When do you set r, and to what?

Humberto

June 21, 2010
by Master_Programmer
Master_Programmer's Avatar

i figured it out....my compiler doesn't make arrays right period. no matter how i changed the variables and stuff, the array kept screwing up. so i made a workaround. after 1 small bug fix, the game will be ready for release.

Post a Reply

Please log in to post a reply.

Did you know that two resistors can be used to make a voltage divider? Learn more...