storing a previously read

hey, does anyone know how to store a previously for example i want to run a loop where and then i want to say if the new = the previous do nothing. or if the new val is different from the previous val than i would want to find the difference... any help would be great...

Just set up another variable. Do the compare first then store the byte in the other variable. This isn't good code it's just an example.

If you need to store more values, realize the arduino has limited ram space. You can store it to flash but it's a lot harder.

int incomingByte = 0; // for incoming serial data int storeByte = 0;

void setup() { Serial.begin(9600); // opens serial port, sets data rate to 9600 bps }

void loop() {

// send data only when you receive data: if (Serial.available() > 0) { // read the incoming byte: incomingByte =;

if (incomingByte != storeByte) { Do what you want here if it's not equal; } //Then store it in storeByte storeByte = incomingByte; } }