Requesting a code review (Arduino/C++)


(Daniel Hollands) #1

Do we have any Arduino/C++ coders here?

I’m working on a small personal project called wildcat, designed to function in a similar way to the “days since last incident” signs you often see in factories:

image

…but to track how long it’s been since our new cat has last misbehaved! (She’s a bit liberal with her claws).

The approach I’ve taken is to use an ESP8266 (Adafruit Feather Huzzah, specifically) with a 16x8 LED matrix to display how long it’s been since the last incident, with a button on the back which lets you reset the timer.

Behind the scenes, this is using Adafruit IO to store a timestamp of the latest incident, which it then uses to calculate how long to show on the display.

(I’m sure I could have done all this locally with a different type of Arduino, a real time clock, and some non-volatile memory, but I don’t have any of those things - plus this gives me the benefit of being able to do things like add Alexa integration at a later date).

Anyway, it’s software side of things is pretty much done (at least for this stage), I just need to figure out the best way of assembling it all - but for now, I’m hoping someone with some Arduino/C++ experience might be able to take a look at my code, please?

I’m using PlatformIO, so if you’re not familiar with this, just take a look at my main.ino file.

I welcome any and all feedback. I’m quite proud of what I’ve gotten so far, but I know it can be better.

Thank you.


(Jon) #2

I’ve done a bit of Arduino, but only using the C-ish default language. I can’t help on C++.

You could try here, it’s a fairly busy community of code reviewers. I haven’t posted there, but I believe it helps if you explain what sort of improvements you’re after e.g. readability/style or performance optimisation etc.


(Daniel Hollands) #3

I didn’t even know this existed. Thank you.


(Jon) #4

No worries - it is a sister to Stack Overflow. They have around 100 community Q&A sites now :star_struck: