Hello, I want to add the RESET PB to this code but I failed .
#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
int Sw1=A1;
int RST=A2;
void setup()
{
Timer1.initialize();
MFS.initialize(&Timer1); // initialize multi-function shield library
}
int counter=0;
byte ended = false;
void loop()
{
if(digitalRead(Sw1)==LOW)
if (counter <=20)
{
MFS.write((int)counter);
counter++;
if(digitalRead(RST) == LOW){
counter = 0;
return;
}
}
else if (!ended)
{
ended = true;
}
delay(50);
}
When I hold the first pushbutton it will count up to 20. Now I want to add the switch 2 to reset to 0
therefore, I can just reverse that to make it count down..
I'm using Multifunction shield.
I want to add the switch 2 to reset to 0
What have you tried ?
Should it second switch only be active when the count is at 20 or at any time ?
therefore, I can just reverse that to make it count down..
Sorry, but I cannot make sense of that in conjunction with the reset to zero.
As written, you only read A2 when A1 is pressed. Is that what you intended ?
what I did till now, I hold the A1 to count up to 20.
what I want to add A2 as A reset button.
so, I want to press A2 to reset to 0
I can't reach to the correct statements for the reset and where exactly to write these statements in the loop.
SultanK1:
what I did till now, I hold the A1 to count up to 20.
what I want to add A2 as A reset button.
so, I want to press A2 to reset to 0
I can't reach to the correct statements for the reset and where exactly to write these statements in the loop.
Think hard about reply #2.
UKHeliBob:
As written, you only read A2 when A1 is pressed. Is that what you intended ?
I just wrote the" RST=A2; " and " if(digitalRead(RST) == LOW) " to try out if it works. but not, and I have to change it. but I don't know how to do that.
It's not what you wrote, it's where you wrote it. 
aarg:
It's not what you wrote, it's where you wrote it. 
I don't understand what you say.
==========
I want to do this addition in code today ASAP.
help out please
SultanK1:
I don't understand what you say.
==========
I want to do this addition in code today ASAP.
help out please
You want to do it, or you want us to do it? Is it a school assignment?
I'm telling you that the lines you wrote to check A2 are in the wrong place. Where it is, it will only run when A1 is held down. Move it to a place in loop() that is outside the test for A1.
aarg:
You want to do it, or you want us to do it? Is it a school assignment?
I'm telling you that the lines you wrote to check A2 are in the wrong place. Where it is, it will only run when A1 is held down. Move it to a place in loop() that is outside the test for A1.
it's not a school Assignment.
I have just tried to change it many many times but it doesn't work.!
I'm not a programmer but it's my hobby.
SultanK1:
it's not a school Assignment.
I have just tried to change it many many times but it doesn't work.!
I'm not a programmer but it's my hobby.
Okay. You have been told what is wrong and how to fix it.
I have just tried to change it many many times but it doesn't work.!
Do as suggested and move the reading of A2 outside the test as to whether A1 is pressed.
If you format your code better then maybe the problem will be more obvious
void loop()
{
if (digitalRead(Sw1) == LOW)
if (counter <= 20)
{
MFS.write(counter);
counter++;
if (digitalRead(RST) == LOW)
{
counter = 0;
return;
}
}
else if (!ended)
{
ended = true;
}
delay(50);
}
The ended variable has no use in this program but I believe that you carried it over from a previous program that put a message on the LEDs when the upper limit was reached.