Being cinephiles.. we had to go .. and we didn´t regret it!
We went to Carré listening to Mr Tarantino talking about his book. Someone interviewed him about his life, and love for movies. He told many anecdotes and side stories. Sometimes with little clips from movies he talked about. We were very lucky to have seats on the 6th row!
The codes are entered using a keypad (Arduino) and send via MQTT
Node Red Dash board
Code
var code = global.get("mysetcode");
var good = 0;
var wrong = 0;
var wrongplace = 0;
var match = false;
var wrongchars = 0;
var wrongplaced = 0;
var goodchars = 0;
var payloadcode = msg.payload.toString();
var usr_input = Array.from(payloadcode);
var secret_code = Array.from(code);
var secret_code1 = secret_code;
if (msg.payload === code) {
match = true;
}
var result = "";
for (var i = 0; i < 4; i++) {
var found = false;
if (usr_input[i] === secret_code[i]) {
usr_input[i] = "a";
secret_code[i] = "b";
good = good + 1;
}
}
for (var i = 0; i < 4; i++) {
var found = false;
for (var j = 0; j < 4; j++) {
if (usr_input[i] === secret_code[j]) {
found = true;
}
}
if (!found) {
wrong = wrong + 1;
}
}
wrongchars = wrong - good;
wrongplaced = 4 - good - wrongchars;
msg.goodchars = good;
msg.wrongchars = wrongchars;
msg.wrongplace = wrongplaced;
msg.result = result;
msg.match = match;
return msg;
When you need a large digital joystick, but only got an analog one. You can use below code to make the joystick act as a digital one.
I’ve played with analog joysticks on digital pins also, it can be done. But it can be buggy, and needs extra code.
Note: The joystick pins are marked with 5V, but when you use a Arduino which can only read till 3.3V using its ADC (Analog Digital Convertors), you can get some weird readings. When moving down and left is reads okay, but up and right react as being connected together! Just try it with 3.3V or use a resistor.
Above shows a ESP32, but below code has Arduino Nano pin names, change accordingly.
CODE
The code gives you a direction only once, you will need to move the stick to the middle position first and then move again.
Below gave me readings between 0 and 1024 (10 bits) Hence the between 350 and 650 for the middle position.
Most will give you a reading between 0 and 4096.
Want to set the resolution yourself?
analogReadResolution(10); // 10 bits
int val1 =0;
int val2 =0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
if (sensorValue1 > 650){
if (val1 == 0){
Serial.print("DOWN");
Serial.println(" ");
val1=1;
}
}
else if (sensorValue1 < 350){
if (val1 == 0){
Serial.print("UP");
Serial.println(" ");
val1=1;
}
}
else if (sensorValue2 > 350 && sensorValue2 < 650){
val1=0;
}
if (sensorValue2 > 650){
if (val2 == 0){
Serial.print("LEFT");
Serial.println(" ");
val2=1;
}
}
else if (sensorValue2 < 350){
if (val2 == 0){
Serial.print("RIGHT");
Serial.println(" ");
val2=1;
}
}
else if (sensorValue2 > 350 && sensorValue2 < 650){
val2=0;
}
delay(100);
}
elcome to Crack the Code!
The code has 4 digits. Each digit is between 0 and 9.
You have 10 tries to guess the code.
After each guess, you will be told how many digits you got correct and how many were misplaced.
Good luck!
Enter your guess: 1234
Guess 1: 1234 - 0 correct, 0 misplaced
Enter your guess: 5678
Guess 2: 5678 - 2 correct, 1 misplaced
Enter your guess: 5689
Guess 3: 5689 - 1 correct, 2 misplaced
Enter your guess: 9688
Guess 4: 9688 - 1 correct, 2 misplaced
....
Sorry, you did not crack the code. The code was 5568.
Generated python code
import random
def generate_code():
code = ""
for i in range(4):
code += str(random.randint(0, 9))
return code
def check_guess(code, guess):
correct_digits = 0
misplaced_digits = 0
for i in range(4):
if guess[i] == code[i]:
correct_digits += 1
elif guess[i] in code:
misplaced_digits += 1
return (correct_digits, misplaced_digits)
def play_game():
print("Welcome to Crack the Code!")
print("The code has 4 digits. Each digit is between 0 and 9.")
print("You have 10 tries to guess the code.")
print("After each guess, you will be told how many digits you got correct and how many were misplaced.")
print("Good luck!")
code = generate_code()
num_guesses = 0
while num_guesses < 10:
guess = input("Enter your guess: ")
if len(guess) != 4 or not guess.isdigit():
print("Invalid input. Please enter a 4-digit number.")
continue
num_guesses += 1
correct, misplaced = check_guess(code, guess)
print(f"Guess {num_guesses}: {guess} - {correct} correct, {misplaced} misplaced")
if correct == 4:
print("Congratulations! You cracked the code!")
return
print(f"Sorry, you did not crack the code. The code was {code}.")
play_game()
After this i let the AI made some changes, which kinda worked. Scary nevertheless
I was thinking of a easier setup which is “static”. Mine has a 65535 possibility setup, but you can make an easy puzzle with below setup.
Set D3 to pinMode(D3, INPUT_PULLUP);
Notice that I’ve placed the wires for some switches at the bottom, so these switches need to be set in the other direction “off” than the others. Only 7 switches matter, you could use all of them. When using a switch with only two connections, place the switch upside-down. Now OFF is switch with ON.
These are last weeks findings, I will add to this page when I discover other useful things.
Platformio
always include “Arduino.h”
Order of functions matter! (Not with Arduino IDE)
setup serial monitor speed in platformio.ini monitor_speed = 115200
Arduino IDE
Build error “panic: runtime error: index out of range [3] with length 3” or length 4. Code probably correct, build with another board and build+upload with correct board as workaround.
Generic
Using a SSD1306 with other pins? For example with Adafruit_SSD1306.h in setup(){ place Wire.begin(5,4);
I’ve build a IR Blaster in the past and tested IR with EspEasy Dev. I’m not happy with my Harmony Hub. Not so much control as i like to have.
So now OpenMqttGateway with IR.
Wemos D1 with IR shieldIR Signal (visible using mobile phone)
I’ve installed platformio in the past. Not really a fan of visual-code i’m showing you the process on CLI
We can’t use the webinstaller or a precompiled binary because we need to change GPIO ports
wget https://github.com/1technophile/OpenMQTTGateway/releases/download/v1.5.0/nodemcuv2-ir-libraries.zip
wget https://github.com/1technophile/OpenMQTTGateway/archive/refs/tags/v1.5.0.tar.gz
tar xzvf v1.5.0.tar.gz
cd v1.5.0/libs
unzip ../../nodemcuv2-ir-libraries.zip
cd ..
edit platformio.ini
remove ; from
default_envs = nodemcuv2-ir
vi main/config_IR.h
search for LOLIN, edit and change into 0 (GPIO 0 = D3)
build and upload
pio run --target upload --upload-port /dev/ttyUSB0
build and upload with flash erase
pio run --target erase --target upload --upload-port /dev/ttyUSB0
clean the environment when needed
pio run -t clean
Now you will get a Access Point, connect and enter your Wifi network information and mqtt server.
When connected you will see the IR codes and if you installed mqtt support in home assistant it will see the mqtt topics.
I’ve copied a json output as was send by my IR remote. Below an example using mosquitto_pub to send codes.
Why use platformio? I know Arduino IDE is easier for starters. Platformio is far more flexible, you can make projects with their own versions of libraries. I like CLI, easier to do version control (git)
pip install -U platformio
pio upgrade
pio update
Some screenshots of my visual code platformio
"If something is worth doing, it's worth overdoing."