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