Calculator keyboard problem

Advice on general approaches or feasibility and discussions about game design

Calculator keyboard problem

Postby awesome101 » Sat Nov 14, 2015 12:36 am

I'm working on a side project of a calculator. I don't know why my code isn't working.
The while loop is for debugging purposes by the way, so that the next frame it won't display another keyboard. I'm trying to convert a string typed into the keyboard into a number by checking if it's the same as a string in an array. If it is, then the number would be the index into the array. The problem is that it doesn't print "Hello World"

Here is the code:

Code: Select all
#include <SPI.h>
#include <Gamebuino.h>

Gamebuino gb;

#define STATE_PROMPT   0
#define STATE_KEYBOARD 1

short state = 0;
char *prompt = "*******PROMPT*******\nPress A to type a\ncommand.\nType the command\n'commands' to show\na list of commands.";

void setup()
{
  gb.begin();
  gb.titleScreen(F("Calculator"));
}

char *commands[3] = {
  "sin", "cos", "tan"
};

void loop()
{
  if(gb.update()) {
    switch(state) {
      case STATE_PROMPT: {
        if(!gb.buttons.pressed(BTN_A)) {
          gb.display.println(prompt);
        } else {
          state = STATE_KEYBOARD;
        }
        break;
      }
      case STATE_KEYBOARD: {
        char* command = "";
        gb.keyboard(command, 4);
        while(true) {
          for(int i = 0;i < 3;i++) {
            char other[4];
            for(int i = 0;i < 3;i++) {
              other[i] = commands[0][i];
            }
            other[3] = '\0';
            if(command == (other)) {
              gb.display.println("Hello World");
            }
          }
          gb.update();
        }
        break;
      }
    }
  }
}


Thanks :D
awesome101
 
Posts: 159
Joined: Sat Jun 20, 2015 6:56 pm

Re: Calculator keyboard problem

Postby awesome101 » Sat Nov 14, 2015 1:02 am

Nevermind, fixed it! :D
awesome101
 
Posts: 159
Joined: Sat Jun 20, 2015 6:56 pm


Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 14 guests

cron