i want to read if there is pulse change on digital input pin of arduino (for example pin4)
i want to do that WITHOUT attachInterrupt,
just in void loop
Do you mean this?
void loop()
{
static int lastValue = false;
int newValue = digitalRead(myPin);
if (lastValue != newValue)
{
// do your value changed stuff
}
// do other stuff
}
i think with that code maybe it will lose some data,
becouse what if on next loop the pin will have the same value? am i wrong?
all i want to do is this
void loop()
{
STAGE_1. check here if there is change on my pin, but here,you have to find it on this time,not on next void loop. this stage can delay enough milliseconds , the master (another arduino) sends pulses on this board like this: high,delaymicroseconds(100),low,delaymicroseconds(100),high.... all time
if there is change store 1 on state variable else store 2
STAGE_2
if (stage==1){
//blabla (my code)
ekse
//blabla (my code)
}
}
If periodic checking of the pin state is not accurate enough, you must use interrupts. There is no other choice.
i was imagine some type of checking on another loop
Sorry - crucial line missing from my code. See below.
I'm still not entirely sure what you are trying to do, but I intend to persist with my answer, even if its not the answer to your question
void loop()
{
static int lastValue = false;
int newValue = digitalRead(myPin);
if (lastValue != newValue)
{
// do your value changed stuff
}
lastValue = newValue;
// do other stuff
}
The 'static' means that lastValue will only be initialised once.