Compare commits
No commits in common. "d198904319d000026627fa11bb3f8566ebb45d53" and "f1f17cf754de60eae6027b4d44e0ad27e55652b9" have entirely different histories.
d198904319
...
f1f17cf754
5
terminal/puzzle_leftRight/.gitignore
vendored
5
terminal/puzzle_leftRight/.gitignore
vendored
@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
; 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
|
|
||||||
lib_deps = adafruit/Adafruit NeoPixel@^1.15.2
|
|
||||||
@ -1,155 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include <Adafruit_NeoPixel.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
Slave Modul 1
|
|
||||||
- Taster an A0 und A1 (INPUT_PULLUP)
|
|
||||||
- 16 Neopixel an D4
|
|
||||||
- D3 -> Master
|
|
||||||
LOW = nicht gelöst
|
|
||||||
HIGH = gelöst (bleibt HIGH)
|
|
||||||
- D2 -> Master
|
|
||||||
HIGH = neue Sequenz generieren
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define LED_PIN 4
|
|
||||||
#define NUM_LEDS 16
|
|
||||||
|
|
||||||
#define POWER_PIN 12
|
|
||||||
bool powerOnState = true;
|
|
||||||
|
|
||||||
#define BUTTON1_PIN A0
|
|
||||||
#define BUTTON2_PIN A1
|
|
||||||
#define austausch_master_pin 3
|
|
||||||
#define randomizer_master_pin 2
|
|
||||||
|
|
||||||
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_RGB + NEO_KHZ800);
|
|
||||||
|
|
||||||
int sequence[NUM_LEDS];
|
|
||||||
int currentStep = 0;
|
|
||||||
bool gameWon = false;
|
|
||||||
|
|
||||||
int lastButton1State = HIGH;
|
|
||||||
int lastButton2State = HIGH;
|
|
||||||
|
|
||||||
int ledIndex(int logical) {
|
|
||||||
return (NUM_LEDS - 1) - logical;
|
|
||||||
}
|
|
||||||
|
|
||||||
void generateNewSequence() {
|
|
||||||
for (int i = 0; i < NUM_LEDS; i++) {
|
|
||||||
sequence[i] = random(0, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAll(uint32_t color) {
|
|
||||||
for (int i = 0; i < NUM_LEDS; i++) {
|
|
||||||
strip.setPixelColor(i, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetGame() {
|
|
||||||
setAll(strip.Color(0, 0, 0));
|
|
||||||
strip.show();
|
|
||||||
currentStep = 0;
|
|
||||||
gameWon = false;
|
|
||||||
digitalWrite(austausch_master_pin, LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
void winAnimation() {
|
|
||||||
strip.show();
|
|
||||||
delay(250);
|
|
||||||
|
|
||||||
setAll(strip.Color(0, 0, 0));
|
|
||||||
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.show();
|
|
||||||
delay(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
setAll(strip.Color(0, 0, w));
|
|
||||||
strip.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkPress(int buttonID) {
|
|
||||||
if (buttonID == sequence[currentStep]) {
|
|
||||||
strip.setPixelColor(
|
|
||||||
ledIndex(currentStep),
|
|
||||||
strip.Color(0, 0, 40)
|
|
||||||
);
|
|
||||||
strip.show();
|
|
||||||
currentStep++;
|
|
||||||
|
|
||||||
if (currentStep >= NUM_LEDS) {
|
|
||||||
winAnimation();
|
|
||||||
gameWon = true;
|
|
||||||
digitalWrite(austausch_master_pin, HIGH);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resetGame();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
pinMode(BUTTON1_PIN, INPUT_PULLUP);
|
|
||||||
pinMode(BUTTON2_PIN, INPUT_PULLUP);
|
|
||||||
pinMode(POWER_PIN, INPUT);
|
|
||||||
powerOnState = digitalRead(POWER_PIN) == HIGH;
|
|
||||||
pinMode(austausch_master_pin, OUTPUT);
|
|
||||||
pinMode(randomizer_master_pin, INPUT);
|
|
||||||
|
|
||||||
digitalWrite(austausch_master_pin, LOW);
|
|
||||||
|
|
||||||
strip.begin();
|
|
||||||
strip.show();
|
|
||||||
|
|
||||||
randomSeed(millis());
|
|
||||||
generateNewSequence();
|
|
||||||
resetGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
//Detecting turn-off
|
|
||||||
if (powerOnState && digitalRead(POWER_PIN) == LOW) {
|
|
||||||
powerOnState = false;
|
|
||||||
resetGame();
|
|
||||||
}
|
|
||||||
//Detecting turn-on
|
|
||||||
if (!powerOnState && digitalRead(POWER_PIN) == HIGH) {
|
|
||||||
powerOnState = true;
|
|
||||||
}
|
|
||||||
if (!powerOnState) {
|
|
||||||
//We are turned-off and stop anything after here
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Master-D2 HIGH → neue Sequenz
|
|
||||||
if (digitalRead(randomizer_master_pin) == HIGH) {
|
|
||||||
generateNewSequence();
|
|
||||||
resetGame();
|
|
||||||
delay(50); // Puls kurz blockieren
|
|
||||||
}
|
|
||||||
|
|
||||||
int currentButton1State = digitalRead(BUTTON1_PIN);
|
|
||||||
int currentButton2State = digitalRead(BUTTON2_PIN);
|
|
||||||
|
|
||||||
if (!gameWon) {
|
|
||||||
if (lastButton1State == HIGH && currentButton1State == LOW) {
|
|
||||||
checkPress(0);
|
|
||||||
delay(200);
|
|
||||||
}
|
|
||||||
if (lastButton2State == HIGH && currentButton2State == LOW) {
|
|
||||||
checkPress(1);
|
|
||||||
delay(200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastButton1State = currentButton1State;
|
|
||||||
lastButton2State = currentButton2State;
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user