|
I just picked up an Arduino to tinker with and, being fairly new to C/C++, I'd like to learn to be as efficient with my coding as possible. I put together a Morse Code Generator that seems to work pretty well, but I'd like to get some feedback on it if anyone's interested. I can PM the code to you - it's 274 lines (compiles to 3,622 bytes), so I don't want to bloat this post with it. About two thirds of that length is devoted to assigning dots and dashes to letters, and this is something I'm a little concerned about - should I be able to do that job in less space?
|
| # ? Mar 2, 2013 05:39 |
|
|
| # ? May 25, 2013 06:32 |
|
I'll help, but I don't have PMs. Just put it up as a gist. Edit: http://gist.github.com
Sinestro fucked around with this message at Mar 2, 2013 around 07:05 |
| # ? Mar 2, 2013 07:01 |
|
There are all kinds of stupid tricks you can do with compressing Morse code encoders and decoders. For example, here's a fun way to store an encoder table: C++ code:The only reason I use the big array notation and the eighth bit is for clarity when reading the code, of course. I could equivalently have written: C++ code:Edit: It's somewhat interesting to note, or at least I am tired enough that it is interesting to me, that if you are encoding Morse-like encodings in this manner, the letters string should never have a character repeat. More specifically, it should be some permutation of the string "\0 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", with the '\0' and ' ' characters always appearing in the first 26 characters (well, at least one, but it's dumb to not have both), and with no cycles under the NEXT operator (which of course only matters for the first 26 characters, as none of the remaining characters are reachable by the NEXT operator). You can generate such strings programatically without too much trouble, so if you ever for some reason need to build a Morse-like encoding on the fly that isn't the real Morse code, building one of these strings is a reasonably cheap means of doing so. Presumably if you are ever going to write an old-school adventure game and require the player to do amateur cryptography to decode an in-game message this may be useful information. ShoulderDaemon fucked around with this message at Mar 2, 2013 around 07:26 |
| # ? Mar 2, 2013 07:10 |
|
Sinestro posted:I'll help, but I don't have PMs. Just put it up as a gist. Edit: http://gist.github.com Thanks - here's the gist.
|
| # ? Mar 2, 2013 15:12 |
|
There is an Arduino thread in DIY. Actually, Arduino language isn't really based on C/C++. It's based on the Processing language, which is actually based on Java. ANIME AKBAR fucked around with this message at Mar 3, 2013 around 02:32 |
| # ? Mar 3, 2013 02:30 |
|
ANIME AKBAR posted:Actually, Arduino language isn't really based on C/C++. It's based on the Processing language, which is actually based on Java. The Arduino language actually is C++. It's not a different language, it's straight-up C++. It has a bunch of macros defined, and a special-purpose standard library, but the language itself is unchanged. The only gotcha is that there isn't an easily-available libstdc++ for the platform, so features which require runtime support like exceptions may not function.
|
| # ? Mar 3, 2013 02:52 |
|
|
| # ? May 25, 2013 06:32 |
|
ANIME AKBAR posted:There is an Arduino thread in DIY. Thanks for the heads up!
|
| # ? Mar 3, 2013 03:17 |






