The Chinese Rings Puzzle with Arduino is my version of a centennial Chinese puzzle.

It is very simple to play and it is an example of a combinatorial puzzle, and lots of patience and concentration is required to solve it. The objective is to untangle the long loop from all nine rings, and the solution takes 341 moves (minimum possible).

Once you learn the method to solve the puzzle, you will see that is very easy to play it! This project is very simple to be assembled, using only an Arduino UNO R3 and a LCD Keypad Shield. It took me some time, but the code I developed reproduced exactly the same conditions and constraints as the original mechanical puzzle. Let's do it and have a fun for a long time!!

## Step 1: Materials

Hardware components:

Arduino UNO & Genuino UNO

Software apps and online services:

Arduino IDE

## Step 2: The Code

The code is as below.

// CHINESE RINGS PUZZLE - V1.2
// Copyright by LAGSILVA // lagsilva@gmail.com // 29.Mai.2017 // // 09 Rings / 341 Moves

#include

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

byte anelOff[8] = { B00000, B00000, B00000, B11111, B00000, B00000, B00000, B00000, };

byte anelOn[8] = { B00100, B01010, B10001, B11111, B10001, B01010, B00100, B00000, };

byte ponteiro[8] = { B00100, B01110, B11111, B00100, B00100, B00100, B00100, B00000, };

String aneis; int px, p1, movimentos,k; int botoes = 0; int estadoBotoes = 0;

#define btDir 1 #define btEsq 2 #define btCima 3 #define btBaixo 4 #define btOk 5 #define btNone 6

// Leitura dos Botoes int ler_botoes() { estadoBotoes = analogRead(0); if (estadoBotoes < 50) return btDir; if (estadoBotoes < 250) return btCima; if (estadoBotoes < 450) return btBaixo; if (estadoBotoes < 650) return btEsq; if (estadoBotoes < 850) return btOk; return btNone; // Retorna None qdo todas as opcoes falharem }

void setup() {

lcd.createChar(0, anelOff); lcd.createChar(1, anelOn); lcd.createChar(2, ponteiro);

lcd.begin(16, 2);

lcd.clear(); lcd.setCursor(1, 0); lcd.print("CHINESE RINGS"); lcd.setCursor(2, 1); lcd.print("by LAGSILVA");

delay(3000);

telaInicial();

}

void loop() {

do { botoes = ler_botoes(); delay(100); } while (botoes == btNone);

delay(100);

switch (botoes) {

case btDir: p1 = aneis.indexOf('1', 1); if (px <= p1) { if (aneis.substring(p1, p1 + 1) == "1") { px = px + 1; } } lcd.setCursor(0, 1); lcd.print(" "); lcd.setCursor(px - 1 , 1); lcd.write(byte(2));

break;

case btEsq:

px = 1; lcd.setCursor(0, 1); lcd.print(" "); lcd.setCursor(px - 1 , 1); lcd.write(byte(2));

break;

case btOk:

if (aneis.substring(px - 1, px) == "1") { if (aneis.substring(px, px + 1) == "1") { aneis.setCharAt(px, '0'); lcd.setCursor(px - 1, 0); lcd.write(byte(0)); } else { aneis.setCharAt(px, '1'); lcd.setCursor(px - 1, 0); lcd.write(byte(1)); } } movimentos = movimentos + 1; lcd.setCursor(12, 1); lcd.print(movimentos);

break;

}

if (aneis == "1000000000") { lcd.clear(); botoes = ler_botoes(); lcd.setCursor(0, 0); lcd.print("CONGRATULATIONS!"); lcd.setCursor(0, 1); lcd.print("Your Grade: "); lcd.print(34100 / movimentos);

do { botoes = ler_botoes(); delay(100); } while (botoes == btNone); delay(500); telaInicial(); }

}

void telaInicial() {

// Imprime Aneis e Estado Inicial lcd.clear(); for (k = 0; k <= 8; k++) { lcd.setCursor(k, 0); lcd.write(byte(1)); } lcd.setCursor(12, 0); lcd.print("Move");

aneis = "1111111111"; movimentos = 0;

px = 1; //Posicao do Ponteiro "^" p1 = 1; //Posicao do Primeiro "1"

lcd.setCursor(p1 - 1, 1); lcd.write(byte(2)); lcd.setCursor(12, 1); lcd.print(movimentos);

}

For this project you will need the Liquid Crystal library.

## Step 3: Playing

The first line of LCD is shown the 09 rings, and in the second line is shown the pointer.

You must use the keys LEFT & RIGHT to move the pointer, and the key SELECT to remove or to insert a ring.

The LEFT key moves the pointer direct to the first ring position, and the RIGHT key moves the pointer one position step by step.

The LCD also shows the total amount of moves, counting every time you press SELECT key to remove or insert a ring.

The key RESTART is used to start again the game at any moment.

At the end, after you solve the puzzle completely, you will see the "Congratulations" message and your grade.

Note: You will see there are some restrictions to move the pointer and also to remove a ring, but this is part of the rules to solve the puzzle.

<p>Hi Adriannn!</p><p>Why did you copy my original project &quot;Chinese Rings Puzzle With Arduino&quot;?</p><p>I had a hard work to develop the project and the code before published here at Instructable and then you republished it don't respecting authoring rights ?</p><p>Are you not embarrassed with this attitude ?</p><p>I hope you delete this copied post as soon as possible!</p><p>LAGSILVA - The original author of this project !!</p>