Dharma Tally Counter

I wrote this application for arduboy. A tally counter with a dharmic bias.

Perhaps it will be useful to someone.
There is nothing special about the counter program itself.
But perhaps someone will be interested in the system of storing the current value of the counters in the EEPROM memory.
To reduce the number of rewrites to the same memory cell, every 100 rewrites the cell is moved to a new random location. The addresses of all ten cells are stored in the address table, which, after 100 rewrites into it, is also moved to a new random location in memory.
Controls:
[A] - increase counter
[B] - reset counter to 0
[UP] - decrease counter
[DOWN] - increase counter
[UP + DOWN] - switch audio ON/OFF
[LEFT] - previous mode
[RIGHT] - next mode

The first three modes (7, 21 and 108) always start at 0.
The ten tally counter modes store the current counter value in the EEPROM. Maximum counting value for the tally counting modes is 999999.

In the ‘Titles.h’ file, you can add titles for the tally counter modes. Changing the title and reuploading of the program do not change the stored counter value!

The project has been modified according to Scott’s comments.

Current version is 1.7

Github repository

DharmaCounter.hex (68.7 KB)

2 Likes

An area at the start of EEPROM is reserved for system use. Sketches must not use this area. Currently the area is 16 bytes long, from address 0 to 15 but sketches should use the defined value
EEPROM_STORAGE_SPACE_START
as the first available EEPROM address.

Please change your sketch to comply.


The sketch has plenty of program space left over, so you should be using arduboy.begin() instead of arduboy.beginDoFirst(). If the reason you’re using beginDoFirst() is to eliminate the ARDUBOY logo sequence, that can be done as a user choice by a setting stored in system EEPROM. You can manipulate the various settings in system EEPROM using the SetSystemEEPROM sketch available as an example in the Arduboy2 library.
File → Examples → Arduboy2 → SetSystemEEPROM

arduboy.begin() should be called at the start of setup() before calls to any other Arduboy2 library functions.


Instead of using randomSeed(analogRead(0)) to seed the random number generator, it would be better to use arduboy.initRandomSeed()


You don’t need to maintain your own EEPROM setting for the sound mute state. You can let the Arduboy2 library’s audio control functions take care of it. Instead of the flag you save at SOUND_ADDR, you can use
arduboy.audio.saveOnOff()
to save the current audio state (that was set using arduboy.audio.off() or arduboy.audio.on()) in system EEPROM.

Instead of maintaining your own sound_on variable, you can test the current mute state using arduboy.audio.enabled()


The call sound.volumeMode(VOLUME_ALWAYS_NORMAL) isn’t really necessary. You could just change the single place you play a high volume note, in decr_sound[] from NOTE_D1H to NOTE_D1

1 Like

Thanks for your comments. I will redo my project accordingly.

So, the project has been updated to Ver. 1.1
I have made all the changes you recommended. Thanks for your kind help.

You must call arduboy.initRandomSeed() after arduboy.begin() because begin() sets up things that initRandomSeed() requires.


Don’t call
arduboy.writeShowBootLogoFlag(false)
or
arduboy.writeShowBootLogoLEDsFlag(false)

By putting these in your sketch, any user that runs it will now have the ARDUBOY logo and LEDs eliminated from every other sketch that they load afterwards.

Let the user (and yourself) decide if they want to see the ARDUBOY logo and LEDs or not. They can configure these using the SetSystemEEPROM sketch.

Done. Thank you.

2 Likes