I've long had a box with a few electronic parts and some micro controllers lying around. Among them are a Raspberry Pi Pico, an Arduino UNO, a small display, a physical switch, an NFC sensor and some other things. I once bought them with a friend, because we had a little project in mind, that sadly never fully came to life. Back then we wanted to build our own little remote-controlled race car.
Since then I've barely touched that box, even though I was tempted a few times. But I lacked a good project idea. Recently, I've gotten an idea though.
What I came up with, is that I want a monitor for my Hive stats. I want to request an API to get information for my accounts, that then gets displayed on a tiny LCD display. That way I could see all important information, even without opening Hive in my browser.
For example, there is the Memo feature on Hive, using which you can send messages to other users easily via the blockchain. Using the Memo Key, those messages can also be encrypted, so they are only readable for sender and recipient. They work by sending a transaction of, for example, 0.001 HIVE with a text attached in the Memo field. But since there are very few ways I know of, to get notifications, once a new transaction has come in, you never know if you've received a message, unless you check your transactions manually. That's something I could simplify for myself, using this display, among other things.
Could my goal be achieved way easier? Yes! Will I still try doing it with a micro controller? Also yes! This is simply a way for me to learn a new skill. And this journey has taken it's first bigger step today, as I started learning C. C is the programming language that is most widely spread for micro controller use-cases. I know a fair bit about Python already, so I do have a head start in learning a new language, but those two languages still differ in pretty much any aspect programming languages can differ in. Comparing C++ and Python is like comparing day and night.
My first project today was a game, where the player has to guess a randomly generated number. A secret number between 1 and 100 is set, then the player will guess until the number is found. After each try, they get a hint, weather the number is higher or lower.
Since it's micro controllers I'll be mainly using C++ for, I already let the games processing be run on my Arduino today, with only the in- and output being displayed to the player on the computer via the serial connection of the board.
The reason it makes sense to use the Arduino for this already is that micro controllers have a fairly low storage capacity. My Arduino Uno has 32 KB of program storage and 2 KB for variables. So using the Uno, already primes me to write efficient code, that doesn't take up to much space, neither in bytes of code, nor in processing intensity. For reference, the code shown below for my guessing game already consumes 14% of the program storage. Though, admittedly I did put a lot of display text into my game, that surely makes up a respectable portion of the storage space used.
Below, I'll paste the code that ran on the board today. If you have any ideas what I could add as functionality or what other fun ideas I could try out for learning, I'm all ears!
// C++|Arduino UNO
int chosenMode = 0;
const String availableModes[] = {"None", "Guess the number"};
void setup() {
Serial.begin(600);
delay(2500);
Serial.println("-*-*-*-*-*-*-*-");
Serial.println("The following Modes are available:");
Serial.println("- [1] Guess The Number");
Serial.println("-*-*-*-*-*-*-*-");
}
void loop() {
if (Serial.available() > 0) {
chosenMode = Serial.parseInt();
Serial.read();
// Guess the number
if (chosenMode == 1) {
randomSeed(analogRead(0));
int gameNumber = random(1,100);
int guessedNumber = 0;
bool gameWon = false;
Serial.println("Enter a number to start guessing!");
while (!gameWon) {
if (Serial.available() > 0) {
guessedNumber = Serial.parseInt();
if (guessedNumber == gameNumber) {
gameWon = true;
Serial.print("You've won the game! The winning number was ");
Serial.println(gameNumber);
} else if (guessedNumber > gameNumber) {
Serial.print("The winning number is LOWER than ");
Serial.println(guessedNumber);
} else if (guessedNumber < gameNumber) {
Serial.print("The winning number is HIGHER than ");
Serial.println(guessedNumber);
} else {
Serial.println("How did we end up here???");
}
Serial.read();
}
}
} else {
}
}
}
![About Revolwritings]
I'm known ason Hive. To keep things I post on here a bit separate, I decided to create multiple accounts for different use-cases. You have just read a post on my "tryout"-account, where I just post things that don't feel like a good fit for my other accounts.
Feel free to check out my other content. Content of all accounts will be reposted on my main account, liked above.
And before I forget, I have a short acknowledgement to make! The idea of posting text and images side-by-side, as seen above, is one I got a few days ago, when reading a post by . After I've been so jealous about his nice formatting, I took a moment to take a look into the json-data on the blockchain, to figure out what his secret is.