Post Reply 
Scientific RPN Calculator (with ATTINY85)
03-20-2018, 01:01 PM
Post: #40
RE: Scientific RPN Calculator (with ATTINY85)
Hello Pauli!

You know that I am not very fast - but finally I took up your hint that the casting of the keycodes to ascii-characters can be done smarter:

(03-08-2018 01:43 AM)Paul Dale Wrote:  * I think buttoncast can be done with the tables by renumbering the KC use 0x00 - 0x0F and some bit operations. A straight log2 of the key scan could be the key code but changes elsewhere (checking for digits using ranges) would need modification. There might be a smarter way.

And you are right. I tried this faster and shorter code with your log2-idea:

Code:
static byte buttoncode() { // Returns byte value with key number
  unsigned int c = getbuttons(); //  1  3  5  7
  if (c & 0x1) return (16);      //  9 11 13 15
  byte ans = NULL;               // 16  2  4  6
  while (c >>= 1) ans++;         //  8 10 12 14
  return (ans);
}

static byte buttoncast() { // Get button pattern and return keycode
  //           key number:      1   10    2   11    3   12    4   13    5   14    6   15    7   16    8    9
  // code of buttoncode():  0   1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16
  byte keycast[KEYS + 1] = {0, 'f', '1', '7', '2', '8', '3', '9', 'c', 'E', '0', '4', '.', '5', ' ', '6', '#'};
  return (keycast[buttoncode()]);
}

And it saves me 40 (!) bytes more - great.

Mayby there are more "gold nuggets" in your former posts ...

Thank you again.
deetee
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Scientific RPN Calculator (with ATTINY85) - deetee - 03-20-2018 01:01 PM



User(s) browsing this thread: 1 Guest(s)