Trust is earned, not given

A different perspective

2019-06-22 · Projects

A math practice toy, part 2: Mixed questions and a score system on the Nano

Part 2from the A math practice toy series · 4 parts in all

Part 2 of the math-toy series, NANO-MathToyMix100-1602, adds what a practice tool actually needs to hold a child's attention: mixed question types (addition, subtraction and multiplication in one session) and a score/streak system displayed on the second row of the LCD.

What changed from part 1

A pattern worth stealing: one function per question type

bool nextQuestion() {
  switch (random(3)) {
    case 0: return askAddition();
    case 1: return askSubtraction();
    case 2: return askMultiplication();
  }
}

Each askX() function generates operands, prints the question, waits for the answer, and returns true/false. The main loop does not know or care which type ran. When you later add a fourth type, you touch exactly two lines. This is the open/closed principle in its smallest form, and it translates directly to professional code.

Series index

Part 1 was the plus/minus original; part 3 moved to a 128x64 graphics LCD; part 4 added WiFi, NTP clock and backlight dimming on ESP8266. All repositories are linked from my GitHub profile.

Repository: github.com/bobhuang1/NANO-MathToyMix100-1602