Hey there all,
I'm trying to understand how this for loop works but I'm a little confused.
To give you context this section is preceded by a for loop that turns all internal pullups on.
So obviously, when digital read goes low it triggers a prerequisite in this loop and changes
an array element.
I will comment in the code to show my own thought process.
If I'm wrong please correct me.
for(int i=0;i<15;i++) //here we loop through the first 15 inputs waiting for a button press
{
if(digitalRead(i)==0) //one of the buttons goes low and triggers this prerequisite
{
if(stis[i]==0) //all of the stis elements are set at 0 already so this if statement is true.
{
if(i<10)
broj=broj+i;
if(i==10)
broj=broj+"+";
if(i==11)
broj=broj+"-";
if(i==12)
broj=broj+"*";
if(i==13)
broj=broj+"/";
if(i==14)
broj=broj+".";
stis[i]=1; //so here the element is changed to 1 so then how would it trigger any of the
} //if statements above if the next line changes that stis element back to 0
}else{stis[i]=0;} //with this line?
}
Would I be correct to say that what happens is the code loops through here once
reads that reads that a button is pressed, changes the stis element to 1, goes back to the
top of the code, checks for a button press again, finds that the element in stis is there and then changes the broj string, then changes the stis element back 0?