I am trying to calculate a speed based on how many pulse's a proximity sensor next to a toothed wheel has generated in an amount of time.
uint32_t varLastSpeedTime;
volatile int16_t vTachoSpeedCounts;
void lcdSpeedPrint() {
uint32_t tempvarTime = millis();
uint32_t vtSpeed = (vTachoSpeedCounts * tachoStep * 600) / (millis() - varLastSpeedTime);
int32_t tvTimeDifference = ((int32_t)tempvarTime - (int32_t)varLastSpeedTime);
char text[6] = {0, 0, 0, 0, 0, 0};
char counter = 0;
char temp;
lcd.print(millis());
lcd.setCursor(0, 2);
lcd.print(vTachoSpeedCounts);
lcd.setCursor(0, 3);
lcd.print(tvTimeDifference, DEC);
varLastSpeedTime = millis();
vTachoSpeedCounts = 0;
The difference between the current time and the last time always results in some randomly low number lik 6 or 9 or 7.
Initially "vTachoSpeedCounts" was called "varTachoSpeedCounts" and it failed to update. I don't know if anything starting with "var" has some other meaning in Arduino but the colour of the text never changed. Unfortunately colour highlighting on the arduino IDE is very limited and you can't tell the difference between things like variables and defined text.