Posts

Showing posts from October, 2019

Arduino Regular Expressions

The first chapter of a wonderful book titled “Beautiful Code” (O’Reilly 2007) was written by Brian Kernighan who described an episode from when he and Rob Pyke were writing a book together called “The Practice of Programming”. They wanted to include a discussion on regular expressions but also wanted to include the code of an implementation. Existing code bases would have been a book length by themselves. Rob Pyke developed 30 lines of C code in less than two hours that implements a substantial part of the day to day usage of regular expressions. The code can be described as beautiful for its elegant efficiency. The final line of the chapter reads “I don’t know of another piece of code that does so much in so few lines while providing such a rich source of insight and further ideas”. The code handles the following constructs: Character Meaning c Matches any literal character (in this case ‘c’) . (full stop) Matches any single character

An Arduino Sudoku Solver

Image
I saw a link to Peter Norvig’s post on “ Solving Every SudokuPuzzle ” on Hacker News where he had constructed a Python program to do just that. His purpose was to cure the world of Sudoku but as Sudoku appears to be an ongoing although mild mental affliction I thought his solution might be worth exploring for the Arduino platform. I had a look at the JavaScript versions linked from the page as my Python knowledge is less even than rudimentary. I also had a good look at the C++ solution posted by Pau Fernandez . My draft plan was to write a solver for the MKR WiFi 1010 platform and to interact with it via an HTML page hosted by that board. Peter Norvig’s post explains how he applied constraint propagation to the task of searching for a solution that does not require waiting for the heat death of the universe to run to completion. Take a look, as he certainly explains it better than I can although I will have a stab at it. A 9 by 9 Sudoku grid contains 81 cells. The rules

Unicode output from an Arduino.

Image
I have been working hard on a second edition for my book called "Practical Arduino C". The new edition has an extra chapter focusing on adding an Internet capability to Arduino boards plus some additional data structures. Overall, the text has been polished and the index extended and tidied. I have also changed the way the book is being published and sold. This has halved the retail price while still ensuring fast delivery when ordered from Amazon ( Amazon UK link here ). One item that featured in the first edition has been dropped as with hindsight it became clear that it did not add to the reader's learning experience. It made sense therefore to move the section on Unicode output over the Arduino serial interface to a blog post here. Unicode Characters The Arduino C is a great tool for manipulating, displaying and communicating ASCII encoded characters, which is perfect if the language you want to use is based upon the Latin character set. Most recent programming