 volatile int old_state = 0;
 volatile int state = 0;
 
+// Value to send to DAC
 volatile int value = 0;
 volatile int new_value = 500;
 

    if (value > 4095) {
      new_value = value = 4095;
    }
    if (value < 64) {
      new_value = value = 64;
    }
  
    dac.setVoltage(value, false);

      new_value--;
    }
  }
  // If bit 4, update the value with a coarse resolution
  if (bitRead(changes, 4)) {
    if (bitRead(state, 4) ^ bitRead(old_state, 5)) {
      new_value += 8;
    } else {
      new_value -= 8;
    }
  }

  // Store the state to compare against next time
  old_state = state;
}
