Compare commits
20 Commits
d198904319
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d501292f32 | |||
| 1974376134 | |||
| 8c0f98b7a7 | |||
| 92a2d39e49 | |||
| 69f1cba2f8 | |||
| e2bf85c91e | |||
| d3f10ea70b | |||
| c2b5331bbd | |||
| 462485dfa6 | |||
| 64cde85752 | |||
| 26ee30d1e9 | |||
| 9df16a82c4 | |||
| 9f964f63d3 | |||
| 3ac09781e5 | |||
| 54ffd02ab4 | |||
| b3322b169b | |||
| dd9ced2962 | |||
| 99014b0f1d | |||
| 210f70a946 | |||
| 5c0c1e5672 |
@@ -43,9 +43,13 @@ unsigned long lockTimer = 0;
|
||||
bool unlocked = false;
|
||||
|
||||
void openLock(uint8_t indexOn) {
|
||||
digitalWrite(schubladen[indexOn].schlossPin, HIGH);
|
||||
delay(400);
|
||||
digitalWrite(schubladen[indexOn].schlossPin, LOW);
|
||||
delay(400);
|
||||
digitalWrite(schubladen[indexOn].schlossPin, HIGH);
|
||||
unlocked = true;
|
||||
lockTimer = millis();
|
||||
digitalWrite(schubladen[indexOn].schlossPin, HIGH);
|
||||
}
|
||||
|
||||
void onI2CReceive(int len) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void resetPuzzles();
|
||||
void resetPuzzles(bool easy);
|
||||
|
||||
/* ========================================================= */
|
||||
const uint8_t ARCHIV_ADDR = 0x10;
|
||||
@@ -70,21 +70,27 @@ ISR(PCINT1_vect)
|
||||
}
|
||||
lastState = state;
|
||||
}
|
||||
|
||||
uint8_t inputPattern = 0;
|
||||
uint8_t secretPattern = 0b10101010;
|
||||
void handleEncoderMovement()
|
||||
{
|
||||
long diff = encoderPostion - lastClickPosition;
|
||||
if (abs(diff) >= stepsPerClick)
|
||||
{
|
||||
resetPuzzles();
|
||||
if (diff > 0)
|
||||
{
|
||||
// right turn
|
||||
selectedIndex = (selectedIndex + 1) % 8;
|
||||
inputPattern = ((inputPattern << 1) | 1) & 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
//left turn
|
||||
selectedIndex = (selectedIndex + 7) % 8;
|
||||
inputPattern = ((inputPattern << 1) | 0) & 0xFF;
|
||||
}
|
||||
bool reset = inputPattern == secretPattern;
|
||||
resetPuzzles(reset);
|
||||
setDrawerLight(selectedIndex);
|
||||
lastClickPosition = encoderPostion;
|
||||
}
|
||||
@@ -133,13 +139,20 @@ const int puzzleResetPins[3] = {7, 8, 9};
|
||||
bool puzzlesSolved[3] = {false, false, false};
|
||||
bool allSolvedSent = false;
|
||||
|
||||
void resetPuzzles()
|
||||
void resetPuzzles(bool easy)
|
||||
{
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
{
|
||||
puzzlesSolved[i] = false;
|
||||
digitalWrite(puzzleResetPins[i], HIGH);
|
||||
delay(30);
|
||||
puzzlesSolved[i] = false;
|
||||
}
|
||||
if (easy)
|
||||
delay(400);
|
||||
else
|
||||
delay(90);
|
||||
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
{
|
||||
digitalWrite(puzzleResetPins[i], LOW);
|
||||
}
|
||||
allSolvedSent = false;
|
||||
|
||||
@@ -127,6 +127,7 @@ NormalizedRGB updateLeft()
|
||||
uint32_t sum = inputR + inputG + inputB;
|
||||
|
||||
NormalizedRGB leftRGB;
|
||||
strip.begin();
|
||||
if (sum > 0)
|
||||
{
|
||||
leftRGB.r = (uint32_t)inputR * MAX_SUM / sum;
|
||||
@@ -138,6 +139,7 @@ NormalizedRGB updateLeft()
|
||||
{
|
||||
strip.setPixelColor(2, strip.Color(0, 0, 0, 0));
|
||||
}
|
||||
strip.show();
|
||||
return leftRGB;
|
||||
}
|
||||
|
||||
@@ -149,7 +151,7 @@ NormalizedRGB updateMiddle()
|
||||
uint32_t sum = inputR + inputG + inputB;
|
||||
|
||||
NormalizedRGB middleRGB;
|
||||
|
||||
strip.begin();
|
||||
if (sum > 0)
|
||||
{
|
||||
middleRGB.r = (uint32_t)inputR * MAX_SUM / sum;
|
||||
@@ -161,6 +163,7 @@ NormalizedRGB updateMiddle()
|
||||
{
|
||||
strip.setPixelColor(1, strip.Color(0, 0, 0, 0));
|
||||
}
|
||||
strip.show();
|
||||
return middleRGB;
|
||||
}
|
||||
|
||||
@@ -172,7 +175,7 @@ NormalizedRGB updateRight()
|
||||
uint32_t sum = inputR + inputG + inputB;
|
||||
|
||||
NormalizedRGB rightRGB;
|
||||
|
||||
strip.begin();
|
||||
if (sum > 0)
|
||||
{
|
||||
rightRGB.r = (uint32_t)inputR * MAX_SUM / sum;
|
||||
@@ -184,7 +187,7 @@ NormalizedRGB updateRight()
|
||||
{
|
||||
strip.setPixelColor(0, strip.Color(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
strip.show();
|
||||
return rightRGB;
|
||||
}
|
||||
|
||||
@@ -211,28 +214,36 @@ NormalizedRGB generateRandomNormalizedRGB(const Section *section, uint8_t from,
|
||||
}
|
||||
|
||||
GameBoard finishedBoard;
|
||||
void generateTargetGameBoard()
|
||||
void generateTargetGameBoard(bool easy)
|
||||
{
|
||||
for (size_t i = 0; i < 6; i++)
|
||||
{
|
||||
slavePotiValues[i] = 0;
|
||||
}
|
||||
digitalWrite(COMPLETED_PIN, LOW);
|
||||
GameBoard board;
|
||||
if (easy)
|
||||
{
|
||||
board.left = generateRandomNormalizedRGB(pot3, 2, 3);
|
||||
board.middle = generateRandomNormalizedRGB(pot4, 3, 4);
|
||||
board.right = generateRandomNormalizedRGB(pot5, 4, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
board.left = generateRandomNormalizedRGB(pot3, 0, 3);
|
||||
board.middle = generateRandomNormalizedRGB(pot4, 0, 4);
|
||||
board.right = generateRandomNormalizedRGB(pot5, 1, 5);
|
||||
}
|
||||
strip.begin();
|
||||
strip.clear();
|
||||
GameBoard board;
|
||||
// left
|
||||
board.left = generateRandomNormalizedRGB(pot3, 0, 3);
|
||||
finishedLeft = false;
|
||||
strip.setPixelColor(3, strip.Color(board.left.r, board.left.g, board.left.b, 0)); // left
|
||||
// middle
|
||||
board.middle = generateRandomNormalizedRGB(pot4, 0, 4);
|
||||
|
||||
finishedMiddle = false;
|
||||
strip.setPixelColor(4, strip.Color(board.middle.r, board.middle.g, board.middle.b, 0)); // middle
|
||||
// right
|
||||
board.right = generateRandomNormalizedRGB(pot5, 1, 5);
|
||||
|
||||
finishedRight = false;
|
||||
strip.setPixelColor(5, strip.Color(board.right.r, board.right.g, board.right.b, 0)); // left
|
||||
//------------------
|
||||
strip.setPixelColor(5, strip.Color(board.right.r, board.right.g, board.right.b, 0)); // right
|
||||
|
||||
finishedBoard = board;
|
||||
strip.show();
|
||||
@@ -260,7 +271,7 @@ void setup()
|
||||
if (powerOnState)
|
||||
{
|
||||
strip.begin();
|
||||
generateTargetGameBoard();
|
||||
generateTargetGameBoard(false);
|
||||
strip.show();
|
||||
}
|
||||
}
|
||||
@@ -297,7 +308,7 @@ void loop()
|
||||
// Detecting turn-on
|
||||
if (!powerOnState && digitalRead(POWER_PIN) == HIGH)
|
||||
{
|
||||
generateTargetGameBoard();
|
||||
generateTargetGameBoard(false);
|
||||
powerOnState = true;
|
||||
}
|
||||
if (!powerOnState)
|
||||
@@ -308,11 +319,14 @@ void loop()
|
||||
|
||||
if (digitalRead(REGENERATE_PIN) == HIGH)
|
||||
{
|
||||
generateTargetGameBoard();
|
||||
delay(50); // Puls kurz blockieren
|
||||
unsigned long resetTimer = millis();
|
||||
while (digitalRead(REGENERATE_PIN) == HIGH)
|
||||
{
|
||||
delay(10);
|
||||
}
|
||||
generateTargetGameBoard(millis() - resetTimer > 150);
|
||||
}
|
||||
|
||||
strip.begin();
|
||||
readExternalPotiValues();
|
||||
|
||||
if (!finishedLeft)
|
||||
@@ -347,7 +361,6 @@ void loop()
|
||||
|
||||
if (finishedLeft && finishedMiddle && finishedRight)
|
||||
{
|
||||
digitalWrite(3, HIGH);
|
||||
digitalWrite(COMPLETED_PIN, HIGH);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
5
terminal/puzzle_colorFade/potiNano/.gitignore
vendored
Normal file
5
terminal/puzzle_colorFade/potiNano/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
14
terminal/puzzle_colorFade/potiNano/platformio.ini
Normal file
14
terminal/puzzle_colorFade/potiNano/platformio.ini
Normal file
@@ -0,0 +1,14 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:nanoatmega328new]
|
||||
platform = atmelavr
|
||||
board = nanoatmega328new
|
||||
framework = arduino
|
||||
39
terminal/puzzle_colorFade/potiNano/src/main.cpp
Normal file
39
terminal/puzzle_colorFade/potiNano/src/main.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#define I2C_SLAVE_ADDRESS 0x08
|
||||
|
||||
volatile uint16_t bufferA[6];
|
||||
volatile uint16_t bufferB[6];
|
||||
|
||||
// Pointer to the buffer currently exposed to ISR
|
||||
volatile uint16_t* activeBuffer = bufferA;
|
||||
|
||||
void onI2CRequest() {
|
||||
// Safe: ISR only reads active buffer
|
||||
Wire.write((uint8_t*)activeBuffer, 6 * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Wire.begin(I2C_SLAVE_ADDRESS);
|
||||
Wire.onRequest(onI2CRequest);
|
||||
analogReference(DEFAULT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Choose the inactive buffer
|
||||
volatile uint16_t* writeBuffer =
|
||||
(activeBuffer == bufferA) ? bufferB : bufferA;
|
||||
|
||||
writeBuffer[0] = analogRead(A0);
|
||||
writeBuffer[1] = analogRead(A1);
|
||||
writeBuffer[2] = analogRead(A2);
|
||||
writeBuffer[3] = analogRead(A3);
|
||||
writeBuffer[4] = analogRead(A6);
|
||||
writeBuffer[5] = analogRead(A7);
|
||||
|
||||
// Atomic pointer swap
|
||||
noInterrupts();
|
||||
activeBuffer = writeBuffer;
|
||||
interrupts();
|
||||
}
|
||||
@@ -97,20 +97,26 @@ bool readButton(uint8_t i) {
|
||||
|
||||
// ------------------ Neues Spiel ------------------
|
||||
|
||||
void generateNewGame() {
|
||||
void generateNewGame(bool easy) {
|
||||
|
||||
for (uint8_t i = 0; i < 6; i++) solutionOrder[i] = i;
|
||||
for (uint8_t i = 0; i < 6; i++)
|
||||
solutionOrder[i] = i;
|
||||
|
||||
for (int i = 5; i > 0; i--) {
|
||||
if (!easy)
|
||||
{
|
||||
for (int i = 5; i > 0; i--)
|
||||
{
|
||||
int j = random(i + 1);
|
||||
uint8_t t = solutionOrder[i];
|
||||
solutionOrder[i] = solutionOrder[j];
|
||||
solutionOrder[j] = t;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < 6; i++)
|
||||
expectedOrder[i] = solutionOrder[5 - i];
|
||||
|
||||
pixelsSolution.begin();
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
uint8_t c = solutionOrder[i];
|
||||
pixelsSolution.setPixelColor(
|
||||
@@ -124,6 +130,7 @@ void generateNewGame() {
|
||||
}
|
||||
pixelsSolution.show();
|
||||
|
||||
pixelsButtons.begin();
|
||||
for (uint8_t i = 0; i < 18; i++) {
|
||||
buttonAssignment[i] = -1;
|
||||
pixelsButtons.setPixelColor(i, 0);
|
||||
@@ -135,12 +142,16 @@ void generateNewGame() {
|
||||
uint8_t idx[18];
|
||||
for (uint8_t i = 0; i < 18; i++) idx[i] = i;
|
||||
|
||||
for (int i = 17; i > 0; i--) {
|
||||
if (!easy)
|
||||
{
|
||||
for (int i = 17; i > 0; i--)
|
||||
{
|
||||
int j = random(i + 1);
|
||||
uint8_t t = idx[i];
|
||||
idx[i] = idx[j];
|
||||
idx[j] = t;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < 6; i++)
|
||||
buttonAssignment[idx[i]] = solutionOrder[i];
|
||||
@@ -220,7 +231,6 @@ void setup() {
|
||||
|
||||
pinMode(PIN_TRIGGER_SHUFFLE, INPUT);
|
||||
pinMode(PIN_POWER_ON, INPUT);
|
||||
powerOnState = digitalRead(PIN_POWER_ON);
|
||||
pinMode(PIN_SEND_WIN, OUTPUT);
|
||||
digitalWrite(PIN_SEND_WIN, LOW);
|
||||
|
||||
@@ -231,16 +241,20 @@ void setup() {
|
||||
pinMode(7, INPUT_PULLUP);
|
||||
pinMode(8, INPUT_PULLUP);
|
||||
|
||||
|
||||
|
||||
for (uint8_t i = 0; i < 12; i++)
|
||||
expander.write(i, HIGH);
|
||||
|
||||
pixelsButtons.begin();
|
||||
pixelsSolution.begin();
|
||||
|
||||
generateNewGame();
|
||||
|
||||
for (uint8_t i = 0; i < 18; i++)
|
||||
lastPressed[i] = false;
|
||||
|
||||
powerOnState = digitalRead(PIN_POWER_ON) == HIGH;
|
||||
|
||||
if (powerOnState)
|
||||
{
|
||||
generateNewGame(false);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------ Loop ------------------
|
||||
@@ -266,7 +280,7 @@ void loop() {
|
||||
// Detecting turn-on
|
||||
if (!powerOnState && digitalRead(PIN_POWER_ON) == HIGH)
|
||||
{
|
||||
generateNewGame();
|
||||
generateNewGame(false);
|
||||
powerOnState = true;
|
||||
}
|
||||
if (!powerOnState)
|
||||
@@ -274,14 +288,18 @@ void loop() {
|
||||
// We are turned-off and stop anything after here
|
||||
return;
|
||||
}
|
||||
unsigned long now = millis();
|
||||
|
||||
bool trigger = digitalRead(PIN_TRIGGER_SHUFFLE);
|
||||
if (trigger && !lastTriggerState) {
|
||||
generateNewGame();
|
||||
if (digitalRead(PIN_TRIGGER_SHUFFLE) == HIGH)
|
||||
{
|
||||
unsigned long resetTimer = millis();
|
||||
while (digitalRead(PIN_TRIGGER_SHUFFLE) == HIGH)
|
||||
{
|
||||
delay(10);
|
||||
}
|
||||
generateNewGame(millis() - resetTimer > 150);
|
||||
}
|
||||
lastTriggerState = trigger;
|
||||
|
||||
unsigned long now = millis();
|
||||
for (uint8_t i = 0; i < 18; i++) {
|
||||
bool pressed = readButton(i);
|
||||
|
||||
|
||||
@@ -36,11 +36,17 @@ int ledIndex(int logical) {
|
||||
return (NUM_LEDS - 1) - logical;
|
||||
}
|
||||
|
||||
void generateNewSequence() {
|
||||
void generateNewSequence(bool easy) {
|
||||
for (int i = 0; i < NUM_LEDS; i++) {
|
||||
if (easy)
|
||||
{
|
||||
sequence[i] = 0;
|
||||
}
|
||||
else {
|
||||
sequence[i] = random(0, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setAll(uint32_t color) {
|
||||
for (int i = 0; i < NUM_LEDS; i++) {
|
||||
@@ -64,17 +70,16 @@ void winAnimation() {
|
||||
strip.show();
|
||||
delay(250);
|
||||
|
||||
uint8_t w = 50;
|
||||
for (int i = 0; i < NUM_LEDS; i++) {
|
||||
strip.setPixelColor(
|
||||
ledIndex(i),
|
||||
strip.Color(0, 0, w)
|
||||
strip.Color(35, 10, 0)
|
||||
);
|
||||
strip.show();
|
||||
delay(20);
|
||||
}
|
||||
|
||||
setAll(strip.Color(0, 0, w));
|
||||
setAll(strip.Color(35, 10, 0));
|
||||
strip.show();
|
||||
}
|
||||
|
||||
@@ -82,7 +87,7 @@ void checkPress(int buttonID) {
|
||||
if (buttonID == sequence[currentStep]) {
|
||||
strip.setPixelColor(
|
||||
ledIndex(currentStep),
|
||||
strip.Color(0, 0, 40)
|
||||
strip.Color(35, 10, 0)
|
||||
);
|
||||
strip.show();
|
||||
currentStep++;
|
||||
@@ -111,10 +116,11 @@ void setup() {
|
||||
strip.show();
|
||||
|
||||
randomSeed(millis());
|
||||
generateNewSequence();
|
||||
generateNewSequence(false);
|
||||
resetGame();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
//Detecting turn-off
|
||||
if (powerOnState && digitalRead(POWER_PIN) == LOW) {
|
||||
@@ -130,10 +136,16 @@ void loop() {
|
||||
return;
|
||||
}
|
||||
// Master-D2 HIGH → neue Sequenz
|
||||
if (digitalRead(randomizer_master_pin) == HIGH) {
|
||||
generateNewSequence();
|
||||
if (digitalRead(randomizer_master_pin) == HIGH)
|
||||
{
|
||||
unsigned long resetTimer = millis();
|
||||
while (digitalRead(randomizer_master_pin) == HIGH)
|
||||
{
|
||||
delay(10);
|
||||
}
|
||||
generateNewSequence(millis() - resetTimer > 150);
|
||||
resetGame();
|
||||
delay(50); // Puls kurz blockieren
|
||||
|
||||
}
|
||||
|
||||
int currentButton1State = digitalRead(BUTTON1_PIN);
|
||||
|
||||
Reference in New Issue
Block a user