0
Offline
Full Member
Karma: 0
Posts: 245
Arduino rocks
|
 |
« Reply #15 on: November 27, 2010, 04:02:23 pm » |
but i want to know if there is change on that pin, not to read if this is high or low
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #16 on: November 27, 2010, 04:13:37 pm » |
On each pass, you need to read the current state of the pin (currValue), and record that. At the end of the loop, save that value as prevValue. Then, a state change has occurred if currValue != prevValue.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 245
Arduino rocks
|
 |
« Reply #17 on: November 27, 2010, 04:19:47 pm » |
i think it is not correct
becouse what if in the begining of the loop the state is 1,in the middle is 0 and goes back to 1 in the end of the loop,where the sketh will store it to compare it?
i want the sketch to know if there is change betwwen the void loop
|
|
|
|
« Last Edit: November 27, 2010, 04:23:49 pm by acmilangr »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #18 on: November 27, 2010, 04:24:32 pm » |
If loop executes fast enough, the chance of a state change occurring in loop is pretty small. But, if the change must be detected immediately, then you must use interrupts, and loop must be written in a way that makes it interrupt-able.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 245
Arduino rocks
|
 |
« Reply #19 on: November 27, 2010, 04:32:26 pm » |
is it posible to enable and disable the interrupt when i want to do it? or how else can i fix my problem?how can i make it interrupt-able? :'( :'(
|
|
|
|
« Last Edit: November 27, 2010, 04:37:02 pm by acmilangr »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #20 on: November 27, 2010, 05:08:37 pm » |
Dry your eyes and quit crying about it.
Is there more to loop than you first posted? If not, there is no reason that polling would not be adequate. Setting some pins HIGH or LOW, or changing pin mode, or performing digital reads does not take much time.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 245
Arduino rocks
|
 |
« Reply #21 on: November 27, 2010, 05:29:06 pm » |
ok i'll try it tomorrow but as i told you i am sure it will not catch 100% the change becouse maybe it will have the same logic value at that time
|
|
|
|
|
Logged
|
|
|
|
|
|