0

I'm trying to make a kernel for a macro-key maker, this is the starting page's code:

char m[] = "What do you want to do? Type the following commands in this "
      "terminal:\nnew  --> Creates a new Keybinding\ndelete  --> Deletes a " 
      "previous Keybind\nlookup --> Find what is bound to a key\n\nTurn off the " 
      "switch to go back to the normal mode.";
Serial.println(m);
Serial.println(String(takenKeybinds) + "/64 Keybinds taken.");

When I run it, the screen displays:

What do you want to do? Type the following commands in this terminal:
new  --> Creates a new Keybinding
delete  --> Deletes a previous Keybind
lookup --> Find what is bound to a key

Turn off the switch to go back to the normal mode.

The last line is missing. Is this a problem with object casting? takenKeybind is an int.

  • does it happen in minimal sketch? – Juraj Feb 25 at 16:33
  • What board are you compiling for? – Majenko Feb 25 at 16:54
0

You should never do this:

Serial.println(String(takenKeybinds) + "/64 Keybinds taken.");

Yes, it should cope with it and append the strings, but that's really nasty even if it does work. And there is absolutely no call to ever do concatenation when printing to serial.

Instead just use:

Serial.print(takenKeybinds);
Serial.println(F("/64 Keybinds taken."));

Note also the use of the F() macro when printing a string literal. This keeps the string in flash and prevents it being copied to RAM, which is just wasteful.

The same with your big long string - it's wasting RAM, and if you never want to modify it, why have it in RAM? Better is:

Serial.println(F("What do you want to do? Type the following commands in this terminal:"));
Serial.println(F("new  --> Creates a new Keybinding"));
Serial.println(F("delete  --> Deletes a previous Keybind"));
Serial.println(F("lookup --> Find what is bound to a key"));
Serial.println();
Serial.println(F("Turn off the switch to go back to the normal mode."));
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.