mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-15 04:01:04 +00:00
72 lines
1.6 KiB
C++
72 lines
1.6 KiB
C++
/**
|
|
Program to create a car monitor display using:
|
|
- Arduino Due
|
|
- a TFT display (https://www.tinytronics.nl/shop/en/displays/tft/3.5-inch-tft-display-320*480-pixels-mega-compatible-ili9486)
|
|
- ELM327 Bluetooth OBD2 scanner
|
|
- FSC-DB004 (BT 836B) bluetooth module
|
|
*/
|
|
|
|
#include "Arduino.h"
|
|
/* include UTFT library */
|
|
#include <UTFT.h>
|
|
|
|
#include "obd2_display.h"
|
|
// #include "obd2_timer.h"
|
|
|
|
#define DEBUG 1
|
|
|
|
/* pins */
|
|
#define PIN_BT_RX 19
|
|
#define PIN_BT_TX 18
|
|
#define PIN_BT_STATE 3 /* connected/disconnected state of BT */
|
|
|
|
extern uint8_t BigFont[];
|
|
extern uint8_t SmallFont[];
|
|
|
|
char should_clear = 1;
|
|
|
|
/* Set the pins for the display and dev board */
|
|
/* Standard Arduino Mega/Due shield : <display model>,38,39,40,41 */
|
|
UTFT display(ILI9486,38,39,40,41);
|
|
|
|
void setup() {
|
|
randomSeed(analogRead(0));
|
|
|
|
#if (DEBUG == 1)
|
|
Serial.begin(9600);
|
|
#endif
|
|
/* Serial1 is bluetooth module, pin 18 and 19. */
|
|
Serial1.begin(115200);
|
|
|
|
/* Init display */
|
|
display.InitLCD();
|
|
display.setFont(BigFont);
|
|
|
|
#if (DEBUG == 1)
|
|
Serial.println("Starting");
|
|
#endif
|
|
|
|
TCCR0A=(1<<WGM01); //Set the CTC mode
|
|
}
|
|
|
|
void loop() {
|
|
// put your main code here, to run repeatedly:
|
|
while (Serial1.available()) {
|
|
char rec = Serial1.read();
|
|
#if (DEBUG == 1)
|
|
Serial.println(rec);
|
|
#endif
|
|
}
|
|
|
|
if (should_clear)
|
|
{
|
|
display.clrScr();
|
|
display.setColor(255, 0, 166);
|
|
display.fillRect(LCD_W/2-200,LCD_H/2-100,LCD_W/2+200,LCD_H/2+100);
|
|
display.setColor(0, 247, 255);
|
|
display.print("OBD2 display yeet",CENTER,LCD_H/2);
|
|
delay(10);
|
|
should_clear = 0;
|
|
}
|
|
}
|