Below is a complete code for the main board. Each of my slaves reports back to the uno when the required parameters are fulfilled, it goes to ground (this happens in milliseconds so that is not the source of the lag I have tested this as 2 pins go to ground at the same time and one is connected to LED and drops out instantly also connected both to LEDs to be sure they both went to ground at the same time). The problem is that there is about 10 seconds lag before a bad order that was reported resets the system. It often takes several seconds for the serial print to come across for any given report (I have tested the voltage at the input pin and it goes to ground instantly but the serial print can be delayed?). The loop seems to have nothing that shouldnt complete in millis??? HELP CONFUSED AND FLUSTERED. commented out the serial prints in an effort to rule that out even though it should not be an issue.
Thanks
int valuesToAdd[5];
int sum;
int WRONG;
void setup() {
for ( int i = 2; i <= 6; i++){ //set pins 2-6 as input
pinMode (i, INPUT);
}
pinMode(9, OUTPUT); //set pin 9 as output
pinMode(8, OUTPUT);
reset(); //sets up variables
Serial.begin(9600); //open serial cmmunication for feedback
Serial.println("begin");
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
delay(2000);
}
for (int i = 2; i <= 6; i++) { //check through pins 2-7 (because using pins 0 and 1 can be bad because they already have other functions)
if (digitalRead(i)==0) { //if the button is pushed
if (valuesToAdd[i-2]!= 0){
sum = sum + valuesToAdd[i - 2]; //i-2 because array starts at index 0
valuesToAdd[i - 2] = 0; //make sure bounce doesn't add another number
// Serial.print("Press detected on button ");
// Serial.print(i - 1);
// Serial.print(" ");
// Serial.print(sum);
// Serial.print(" ");
// Serial.println(WRONG);
// i = 1000; // causes loop to exit if a press is detected. Prevents multiple buttons from being read in one pass
}
}
}
if (sum != 0 && sum != 2 && sum != 6 && sum != 13 && sum != 22 && sum != 45) { //if the sum is not any prescribed value, reset
WRONG = 1;
}
if (sum == 45) { // if all buttons pressed in correct order
if (WRONG == 0) {
digitalWrite(9, LOW); // code to trigger output
Serial.println("WINNER!\nWINNER!");
delay(150000);
digitalWrite(9, HIGH);
reset();
}
else { digitalWrite (8, LOW);
reset();
delay(500);
digitalWrite (8, HIGH);
delay(2000);
Serial.println ("loser");}
}
}
both of those conditions happen after the main loop and are required functions for the results desired, after the sum of 45 is reached. The problem is that the initial loop should report instantly and does not.
Secondly, the reason of "10 seconds lag" is the delay() function. DO NOT use delay function, use timestamp instead, see BlinkWithoutDelay example
The code below has ZERO delays in it. And therefore not the issue for why the loop doesnt immediately report when the slave mini reports in. There are no delays written into the code until AFTER the sum reaches 45. THOSE DELAYS are NECESSARY for the result of the program. An object must be turned off for 2.5 minutes.
Does anyone see any reason in the code shown in this reply below that could cause a problem that when the pin goes low it doesnt instantly report that condition, add the sum, and print it to the serial?
void loop() {
for (int i = 2; i <= 6; i++) { //check through pins 2-7 (because using pins 0 and 1 can be bad because they already have other functions)
if (digitalRead(i)==0) { //if the button is pushed
if (valuesToAdd[i-2]!= 0){
sum = sum + valuesToAdd[i - 2]; //i-2 because array starts at index 0
valuesToAdd[i - 2] = 0; //make sure bounce doesn't add another number
// Serial.print("Press detected on button ");
// Serial.print(i - 1);
// Serial.print(" ");
// Serial.print(sum);
// Serial.print(" ");
// Serial.println(WRONG);
// i = 1000; // causes loop to exit if a press is detected. Prevents multiple buttons from being read in one pass
}
}
}
if (sum != 0 && sum != 2 && sum != 6 && sum != 13 && sum != 22 && sum != 45) { //if the sum is not any prescribed value, reset
WRONG = 1;
}
Seemingly, you detect the pressing event is incorrect. The pressing event is detected when the button's state change from LOW to HIGH in case of pull-down, or HIGH to LOW in case of pull-up. See the detail.
Secondly, the reason of "10 seconds lag" is the delay() function. DO NOT use delay function, use timestamp instead, see BlinkWithoutDelay example
The "button" is not actually a button. It is an arduino pro mini reporting to an uno that the output is putting out 5v to the uno pin so when it goes low the uno knows it so no.... it is not floating. There is no bounce that has been handled in the code shown.
As far as timestamps im not a fan. And the delay in question is occuring in areas of the code that do not include any delays written in.
TINMAN265/tinvestor we only allow one account per person here. Please tell me which of your two accounts you would like to keep. I'll delete the other one. If I don't get an answer within 24 hours, I'll just pick one to delete.
tinvestor:
Thank You D+<k
That sort of attitude will not be tolerated here. You were asked to learn how to follow the forum rules. Instead of doing so, you gave a rude answer and continued to incorrectly post code. You're here asking for help from volunteers who spend their spare time sharing expertise out of the goodness of their hearts. See how far acting disrespectfully will get you on this forum.
IoT_hobbyist:
Seemingly, you detect the pressing event is incorrect. The pressing event is detected when the button's state change from LOW to HIGH in case of pull-down, or HIGH to LOW in case of pull-up. See the detail.
Thanks, it is not technically a button push. It is an arduino pro mini that has a 5v output to the uno until the conditions are satisfied and then the pin goes to ground. Is there something you see specifically that would cause delay in that portion of the loop?
with the exception of the delay in question (just the lag between when the pro mini pin goes low and when the uno actually reports it, up to 4 seconds per event) the program performs exactly as expected.
TO ANSWER THE QUESTION ABOUT MY KNOWLEDGE OF THE PROJECT... Apparently I had forgotten I had an account and I created a new one some time ago. This was over the course of two years. This computer (not the one I was using this AM) apparently had my original account log in info stored. Sorry for any confusion this may have caused didnt even realize I was using a different account.
if (sum != 0 && sum != 2 && sum != 6 && sum != 13 && sum != 22 && sum != 45) { //if the sum is not any prescribed value, reset
WRONG = 1;
}
Is there any specific order in which the inputs go active? Because the numbers you are checking against sum do not cover all the possible permutations of adding 2, 4, 7, 9, and 23 in all possible random orders, that would be something like 0, 2, 4, 6, 7, 9, 11, 13, 16, 23, 25, 27, 30, 32, if I am adding correctly.
The reason for the specific sums is to check order. If there is a more elegant example of a way to write a code that checks order I am definitely open to suggestions this was just my gut instinct was to use math to confirm that the order was correct
tinvestor:
TO ANSWER THE QUESTION ABOUT MY KNOWLEDGE OF THE PROJECT... Apparently I had forgotten I had an account and I created a new one some time ago. This was over the course of two years. This computer (not the one I was using this AM) apparently had my original account log in info stored. Sorry for any confusion this may have caused didnt even realize I was using a different account.
OK, well let's get rid of one of these accounts. Often people with multiple accounts are up to no good. I understand now that in your case there was no malicious intent, but as this thread demonstrates, it still leads to confusion. Please let me know which one you want to keep so I can delete the other one. Then make sure you have the correct login info on all your computers.