バイクサーキットでラップを測りたい!
けどレンタル代が掛かる!
ってことで作っちゃいました(てへぺろ)
もし利用される場合はアレンジを加えてもいいと思います

<<仕様>>
- GPSを使用したラップタイマー
- Amazonですべて購入可能
- 設定した原点に近づくと勝手にラップが計測される
- ラップは三周分まで表示できる
<<使ったもの>>
- プロトタイプモジュール+配線用ケーブル
- GPSモジュール NEO6M
<<接続>>
M5Stack---NEO 6M
5V---VCC
17(UART2/TX)---RX
16(UART2/RX)---TX
GND---GND
<<使用するライブラリー>>
M5Stack.h
TinyGPS++.h
<<スケッチ(β)>>
#include <M5Stack.h>
#include <TinyGPS++.h>
TinyGPSPlus gps;
int YEAR, MONTH, DAY, HOUR, MINUTE, SECOND;
float LAT, LONG, KMPH, ALTITUDE;
float LAT0 , LONG0, distanceToMeter0, LAP, LAP1, LAP2, LAP3;
float TIME, LAPTIME;
boolean LAPCOUNTNOW;
float LAPRAD = 10;//ラップ計測のトリガー(原点からの半径)距離
void setup() {
Serial.begin(115200);
Serial2.begin(9600);
M5.begin();
M5.Speaker.end();
M5.Lcd.setBrightness(255);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(10, 10);
M5.Lcd.print("Start");
}
void loop()
{
//**********GPSから値を読み込み代入
ReadGPS();
//**********条件によるラップ計測
CountLAP();
//**********M5Stackへ描画
showvalue(1000);
}
void ReadGPS()
{
//**********GPS形式をライブラリで扱えるよう変換
while (Serial2.available() > 0)
{
char c = Serial2.read();
gps.encode(c);
Serial.write(c);
}
//**********GPSデーターをもとに各値へ変換
LAT = gps.location.lat();
LONG = gps.location.lng();
YEAR = gps.date.year();
MONTH = gps.date.month();
DAY = gps.date.day();
HOUR = gps.time.hour();
MINUTE = gps.time.minute();
SECOND = gps.time.second();
KMPH = gps.speed.kmph();
ALTITUDE = gps.altitude.meters() ;
distanceToMeter0 = gps.distanceBetween(gps.location.lat(), gps.location.lng(), LAT0, LONG0) ;
//**********日本標準時(JST)へ変換
HOUR += 9;
if (HOUR >= 24)
{
DAY += HOUR / 24;
HOUR = HOUR % 24;
}
//**********相対距離原点設定
M5.update();
if (M5.BtnB.isPressed())
{
LAT0 = LAT;
LONG0 = LONG;
distanceToMeter0 = gps.distanceBetween(gps.location.lat(), gps.location.lng(), LAT0, LONG0) ;
}
}
void CountLAP()
{
//**********ボタンAによるラップ計測
if (M5.BtnA.isPressed())
{
LAP3 = LAP2;
LAP2 = LAP1;
LAP1 = LAP;
LAPTIME = millis() - TIME;
LAP = LAPTIME / 1000;
TIME = millis();
delay(200);
}
//**********相対距離によるラップ計測
if ( distanceToMeter0 >= LAPRAD)
{
LAPCOUNTNOW = false;
}
if (distanceToMeter0 != 0 && distanceToMeter0 <= LAPRAD && LAPCOUNTNOW == false)
{
LAP3 = LAP2;
LAP2 = LAP1;
LAP1 = LAP;
LAPTIME = millis() - TIME;
LAP = LAPTIME / 1000;
TIME = millis();
delay(200);
LAPCOUNTNOW = true;
}
}
void showvalue(int dulation) {
if (millis() % dulation == 0)
{
//**********ボタン説明
M5.Lcd.clear();
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(40, 228);
M5.Lcd.print("Lap Count");
M5.Lcd.setCursor(115, 228);
M5.Lcd.print("SET Zero-Point");
M5.Lcd.setCursor(220, 228);
M5.Lcd.print("Rad= ");
M5.Lcd.print(LAPRAD);
M5.Lcd.print(" m");
//**********時刻表示
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(5, 0);
M5.Lcd.print(YEAR);
M5.Lcd.print("/");
M5.Lcd.print(MONTH);
M5.Lcd.print("/");
M5.Lcd.print(DAY);
M5.Lcd.print(" ");
M5.Lcd.print(HOUR);
M5.Lcd.print(":");
M5.Lcd.print(MINUTE);
M5.Lcd.print(":");
M5.Lcd.println(SECOND);
//**********標高表示
M5.Lcd.setTextColor(GREEN);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(240, 5);
M5.Lcd.print("Alt ");
M5.Lcd.print(ALTITUDE, 1);
M5.Lcd.print(" m");
//**********時速表示
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(20, 25);
M5.Lcd.setTextSize(3);
M5.Lcd.print(KMPH, 1);
M5.Lcd.setTextSize(2);
M5.Lcd.print(" km/h");
//**********タイム表示
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(200, 30);
M5.Lcd.setTextSize(2);
M5.Lcd.print((millis() - TIME) / 1000, 3);
M5.Lcd.setTextSize(2);
M5.Lcd.print(" s");
//**********ラップ表示
M5.Lcd.fillRect(10, 60, 300, 110, ORANGE);
M5.Lcd.setTextColor(BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.setCursor(20, 80);
M5.Lcd.print("LAP:");
M5.Lcd.setCursor(100, 70);
M5.Lcd.setTextSize(5);
M5.Lcd.print(LAP, 3);
//**********ラップ履歴表示
M5.Lcd.setTextColor(BLACK);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(0, 115);
M5.Lcd.print(" LAP1: ");
M5.Lcd.println(LAP1, 3);
M5.Lcd.print(" LAP2: ");
M5.Lcd.println(LAP2, 3);
M5.Lcd.print(" LAP3: ");
M5.Lcd.println(LAP3, 3);
//**********緯度表示
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(30, 175);
M5.Lcd.print("LAT= ");
M5.Lcd.println(LAT, 10);
//**********経度表示
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(180, 175);
M5.Lcd.print("LONG=");
M5.Lcd.println(LONG, 10);
//**********緯度原点表示
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(30, 190);
M5.Lcd.print("LAT0=");
M5.Lcd.println(LAT0, 10);
//**********経度原点表示
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(180, 190);
M5.Lcd.print("LONG0=");
M5.Lcd.println(LONG0, 10);
//**********原点との相対距離表示
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(30, 205);
M5.Lcd.print("Distance=");
M5.Lcd.setTextSize(2);
M5.Lcd.print(distanceToMeter0, 3);
M5.Lcd.print(" m");
}
}
<<使用方法>>
真ん中ボタンでラップ計測地点をセット
左ボタンで手動ラップ計測