rewrite to prevent delay() lost data
This commit is contained in:
parent
55dc602329
commit
f6ea5f6ab9
42
can/can.ino
42
can/can.ino
@ -9,6 +9,15 @@ LiquidCrystal_I2C lcd(0x27, 20, 4);
|
||||
MCP_CAN CAN(CAN_CS);
|
||||
|
||||
const byte NODE_ID = 0x01; // Change to your Sevcon node ID
|
||||
const unsigned long timing = 500;
|
||||
|
||||
unsigned long previous_time = 0;
|
||||
unsigned long current_time = 0;
|
||||
|
||||
int16_t rpm = 0;
|
||||
int16_t ubat = 0;
|
||||
int v = 0;
|
||||
int ubatr = 0;
|
||||
|
||||
void setup() {
|
||||
lcd.init();
|
||||
@ -48,27 +57,28 @@ void loop() {
|
||||
|
||||
switch (rxId) {
|
||||
case 0x382 : {
|
||||
int16_t rpm = buf[0] | (buf[1] << 8);
|
||||
int v = rpm * 0.017;
|
||||
Serial.print(v);
|
||||
Serial.println();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("vitesse = ");
|
||||
lcd.print(v);
|
||||
lcd.print(" km/h ");
|
||||
delay(400);
|
||||
rpm = buf[0] | (buf[1] << 8);
|
||||
v = rpm * 0.017;
|
||||
Serial.println(v);
|
||||
}
|
||||
case 0x209 : {
|
||||
int16_t ubat = buf[0] | (buf[1] << 8);
|
||||
int ubatr = ubat / 16;
|
||||
Serial.print(ubat);
|
||||
Serial.println();
|
||||
ubat = buf[0] | (buf[1] << 8);
|
||||
ubatr = ubat / 16;
|
||||
Serial.println(ubatr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
current_time = millis();
|
||||
if( current_time - previous_time >= timing){
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Vitesse = ");
|
||||
lcd.print(v);
|
||||
lcd.print(" km/h ");
|
||||
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("ubat = ");
|
||||
lcd.print(ubatr);
|
||||
lcd.print(" V ");
|
||||
delay(400);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user