Build Sudoku program using spare parts
Last year we had the Nextion (NX4827T043) used in the holiday light control project.
Using this same display I wanted to build a Sudoku puzzle program. Rather than using the GUI to build all the pieces and then just update the text on the screen I thought I would come at it a different way.
I first built a simple GUI interface that defined only three fonts that were of different sizes. From there I would build all the graphics using just the P1 and a custom Nextion library with basic functions for drawing lines and circles and filled rectangles.
Here is a sample of that screen generated by the P1:
Sudoku requires several matrixes and a lot of matrix logic to build this screen. In addition the program checks for bad answers in cells and rows. If it sees this, it highlights those numbers.
The program also looks for possible answers to a location and records them. For example if the only number left in a row or column is one of three numbers.
All this code is written in C so SimpleIDE is required to put this altogether.
The library makes use of the Full Duplex Object to capture screen event in the background. This allows picking numbers that you want to put in a location. Then the puzzle is redrawn to show the results.
At 9600 baud the screen updates take some time to happen and changing the default baud to something a little bit faster would be good.
To build the base puzzle I needed 9 squares by 9 squares. Using the 270 pixels and dividing by 9 you get 30 as the answer. This leaves 210 pixel to the right of the puzzle for other information such as the number to use and maybe hints.
The attached zip file contains the custom library with documentation along with the Sudoku puzzle program with a default puzzle.
I would like to add the hint function since all the code is already there just not displayed and disk support to allow loading puzzles from an SD card. This could be an issue since the disk support uses a lot of program space.
Neat. I've been working with the Nextion again this past week and have also put together an integrated driver for it (Spin 1).
I have updated the program a little bit by adding in the Hint function that shows possible values for a given cell position.
Given that the smallest font only allows three number to show in a cell I only show possible hints when there are less than 4 values available.
To determine possible values available for a cell you only need to look at the row and column values that are used in addition to the values in the current Cell. Remember only one number can be used in a given row or column including the cell values.
I also added a Wait/Ready indicator for when the screen is being updated.
In adding the hint function I found some bugs that need to fix and change an array to short integers to handle a bit function.
Since last years project was about the P2 and Nextion I have also created a Sudoku project for that platform as well using FlexProp in this case.
Here is the code and libraries to make that work.