PDA

View Full Version : Detecting change on software inputs



Christopher4187
- 25th July 2012, 17:14
I'm not sure how to do this but I need to compare two or three (could be up to 8) values and whichever one changes, make that new value a different variable. I don't want to use an if/then statement because I need to check a lot of these variables and I'm trying to keep code space at a minimum.

So it would be something like this (This isn't ode, it's just a view on how I want it to work):

PACKET 1: A=10, B=20, C=30 STARTING POINT, NO CHANGE.
PACKET 2: A=10, B=22, C=30 - LIGHT = 22
PACKET 3: A=10, B=22, C=37 - LIGHT = 37
PACKET 4: A=15, B=22, C=37 - LIGHT = 15
PACKET 5: A=15, B=22, C=09 - LIGHT = 09
PACKET 6: A=15, B=22, C=09 - LIGHT = 09
PACKET 7: A=15, B=22, C=09 - LIGHT = 09
PACKET 8: A=03, B=22, C=09 - LIGHT = 03
PACKET 9: A=03, B=21, C=09 - LIGHT = 21
PACKET 10: A=03, B=21, C=24 - LIGHT = 24


Is there a way to do this efficiently?



Is there an easier way?

Darrel Taylor
- 25th July 2012, 18:21
Here's one way ...


Packet_Size CON 3
Old_Packet VAR BYTE[Packet_Size]
New_Packet VAR BYTE[Packet_Size]
Idx VAR BYTE
LIGHT VAR BYTE

FOR Idx = 0 TO Packet_Size - 1
IF (Old_Packet(Idx) ^ New_Packet(Idx)) > 0 THEN LIGHT = New_Packet(Idx)
Old_Packet(Idx) = New_Packet(Idx)
NEXT Idx