Forum Rule: Always post complete source code & details to reproduce any issue!
-
variable update::: general advice needed
Hello,
I was hoping someone could tell me a way to retain information in a variable temporarily until it could be evaluated.
something like this :::
serial available
read byte
byte = previous byte
if byte != previous byte
How can you keep track of a change?
Thanks
-
A class static/auto or global variable is needed where you can copy the last byte to and check later on
Simply can put it before the void setup() line:
Code:
uint8_t lastByte = 0;
void setup() {
....
-
I read about that but I don't get it.
Lets say you say Byte = lastByte, how do you every make lastByte stop updating and look at the previous Byte?
Thanks
-
okay sorry what about this::::
analogread = x
x=preeviousx
print previousx
how do you look at previousx?
TY
-
After you compare it:
myByte == lastByte, or however you wish to compare, then set it to the new value:
lastByte = myByte;
Then your code repeats it
-

Originally Posted by
tonton81
After you compare it:
myByte == lastByte, or however you wish to compare, then set it to the new value:
lastByte = myByte;
Then your code repeats it
I haven't tried that but I did figure out something that works:::
read = a
read = b
read = c
read = d
read = e
if a != b || c || d || e
something to that effect you can see when it changes and compare.
I'll try what you mentioned.. thanks
-
Code:
if ( Serial.available() ) {
uint8_t receivedByte = Serial.read();
if ( receivedByte != lastByte ) {
//Do Something...
}
lastByte = receivedByte; // store the last byte as previous byte
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules