Topics

Games
Sound & Music
Watches & Clocks
Wireless
GPS
Power Supplies
Computers
Graphics
Lighting
Thermometers
Educational
Wearables
Test Equipment
Tutorials
Libraries
PCB-Based Projects

By processor

AVR ATtiny

ATtiny10
ATtiny2313
ATtiny84
ATtiny841
ATtiny85
ATtiny861
ATtiny88

AVR ATmega

ATmega328
ATmega1284

AVR 0, 1, and 2-series

ATmega1608
ATmega4808
ATmega4809
ATtiny1604
ATtiny1614
ATtiny202
ATtiny3216
ATtiny3224
ATtiny3227
ATtiny402
ATtiny404
ATtiny414
ATtiny814

AVR DA/DB/DD-series

AVR128DA28
AVR128DA32
AVR128DA48
AVR128DB28
AVR128DB48
AVR64DD14
AVR32DD28

ARM

ATSAMD21
RP2040
RA4M1

RISC-V

ESP32-P4

About me

  • About me
  • Twitter
  • Mastodon

Feeds

RSS feed

Bulls & Cows Game 2

31st March 2015

This article describes an improved version of my Bulls and Cows Game, which thinks of a code for you to guess, and tries simultaneously to guess a code you have thought of.

The circuit is unchanged from the original article; it's based on an ATmega328 or Arduino Uno driving a 6-digit seven-segment display, with a 10-key keypad.

The improvements are as follows:

Sleep function

The program automatically goes to sleep after 30 seconds to preserve the battery, and avoid the need for an on/off switch. Press the "*" key to wake up from sleep.

The current consumption during sleep is less than 2µA, a negligible drain on the battery. I power the prototype from a 40mAh 3.7V Lipo battery fitted under the keypad.

Improved play

The original program averaged about 6.4 turns to guess the player's number. This new version of the program improves this to about 6.1 turns by making the first two guesses use a random selection of eight of the possible digits. It achieves this using an array Mix[] which contains a jumbled list of the ten possible digits, and then chooses the first two guesses from these.

Games won

At the end of each game the program displays the number of games won by the human and computer; for example, if the human has won 15 games and the computer has won 12 it displays:

h15.c12

Give up

To give up trying to guess the computer's code you can press "#" when the "----" prompt is shown. The computer's code is displayed, and the totals of the games won are reset to 0. The "#" key still also has its original function of allowing you to clear an entered number.

Using the 8MHz internal clock

You can make the game play faster by using the internal 8MHz clock rather than the default 1MHz clock. To do this first add the following lines to the boards.txt file in your Arduino application:

##############################################################
atmega328-8.name=ATmega328p (internal 8 MHz clock)
atmega328-8.bootloader.low_fuses=0xe2
atmega328-8.bootloader.high_fuses=0xd9
atmega328-8.bootloader.extended_fuses=0x07
atmega328-8.upload.maximum_size=32768
atmega328-8.build.mcu=atmega328p
atmega328-8.build.f_cpu=8000000L
atmega328-8.build.core=arduino
atmega328-8.build.variant=standard

This adds an ATmega328p (internal 8 MHz clock) option to the Boards menu. Select this and choose Burn Bootloader to set the fuses. Then upload the program to the processor in the usual way.

For information about uploading the program see the original article: Bulls and Cows Game.

Here's the new version of the program: Bulls & Cows Program with Sleep.


blog comments powered by Disqus