hmmm, i checked the update, and its still turning on the main 4 leds, i feel like their is a rogue lastInputState[i] somewhere causing problems
or its some other piece of code entirely
Edit: no, its not that
hmmm, i checked the update, and its still turning on the main 4 leds, i feel like their is a rogue lastInputState[i] somewhere causing problems
or its some other piece of code entirely
Edit: no, its not that
found an interesting development currentStep is actually responsible for the leds to work properly, but i dont know how to control currentStep
OMG forum i solved it
turns out the cables were badly placed, thank you everyone for thr massive help!
Do you have better code than in #1? Please post it.
its definetly better than 1#, but not much different no, just some minor tweaks here and there, but it works now
however, i will link an image on the project
#define DEBUG
const byte numInputs = 4;
const byte inputPins[numInputs] = {2, 3, 4, 5};
const byte numSteps = 7;
const byte steps[numSteps] = {0, 1, 2, 3, 2, 1, 0};
const byte ledPins[numSteps] = { 6, 7, 8, 9, 10, 12, 13 };
const byte lockPin = A0;
bool lastInputState[] = { HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH };
int currentStep = 0;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
for (int i = 0; i < numInputs; i++) {
pinMode(inputPins[i], INPUT_PULLUP);
}
for (int i = 0; i < numSteps; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(lockPin, OUTPUT);
digitalWrite(lockPin, HIGH);
#ifdef DEBUG
Serial.begin(9600);
Serial.println("Serial Communication Started");
#endif
}
void loop() {
if ((millis() - lastDebounceTime > debounceDelay)) {
for (int i = 0; i < numInputs; i++) {
int currentInputState = digitalRead(inputPins[i]);
if (currentInputState != lastInputState[i]) {
lastDebounceTime = millis();
}
if (currentInputState == LOW && lastInputState[i] == HIGH) {
if (steps[currentStep] == i) {
currentStep++;
#ifdef DEBUG
Serial.print(F("Nice, Onto the next step #"));
Serial.println(currentStep);
#endif
} else {
currentStep = 0;
Serial.println("Not Right! Start From Scratch");
}
}
lastInputState[i] = currentInputState;
}
}
if (currentStep == numSteps) {
onSolved();
}
for (int i = 0; i < numSteps; i++) {
digitalWrite(ledPins[i], (i < currentStep ? HIGH : LOW));
}
}
void onSolved() {
digitalWrite(lockPin, LOW);
while (true) {
for (int i = 0; i < numSteps; i++) {
digitalWrite(ledPins[i], HIGH);
delay(100);
}
delay(100);
for (int i = 0; i < numSteps; i++) {
digitalWrite(ledPins[i], HIGH);
delay(100);
}
}
}
Now go for some low-hanging fruit.
After it unlocks do something interesting like a little light show on the LEDs (yes I know, go with me here) for some time then relock and reset, ready to go again.
Next you could make it a game so when it did reset, it calculated a new combination.
Then you could have a mode where the combination always takes the maximum number of trials. You could call it cheating on the part of the sketch.
You need a symmetric delay in your unlocked thing, I did different times like
for (int ii = 0; ii < numSteps; ii++) {
digitalWrite(ledPins[ii], HIGH);
delay(67);
}
delay(400);
for (int ii = 0; ii < numSteps; ii++) {
digitalWrite(ledPins[ii], LOW);
delay(67);
}
delay(600);
It dwells a bit they are all on, it dwells a bit longer they are all off.
a7
@ventage_0, do not cross-post. Other thread locked.
ouch.
Dont you want to close this topic, too, as it is the same subject as your other, closed, topics? But first, a snarky closing, amirite?!