BOM list
- Arduino nano
- GPSモジュール
- LCD
- DC/DC conv.(Lipo to 5V昇圧)
- AMS1117-3.3(GPSモジュール用LDO)
- DHT11(温度湿度モジュール)
スケッチ(if文の羅列で恥ずかしい)
includeの<>を半角に書き換える事
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
//LiquidCrystal_I2C lcd(0x3F, 16, 2);
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display
TinyGPSPlus gps;
SoftwareSerial gpsSerial(4, 3);
const int serialTime = 200;
void setup() {
Wire.begin();
Wire.beginTransmission(0x27);
gpsSerial.begin(9600);
lcd.init();
lcd.begin(16, 4);
lcd.home();
lcd.clear();
lcd.setBacklight(255);
Serial.begin(9600);
}
void loop() {
int start = millis();
int now = millis();
do {
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
}
now = millis();
} while ((now - start) < serialTime);
//--- time ---
if (gps.time.isUpdated())
{
int h = (gps.time.hour()) + 9;
if ( 24 <= h ) {
h = h - 24;
}
lcd.setCursor(0, 0);
if (h < 10) {
lcd.print(" ");
lcd.setCursor(1, 0);
}
lcd.print(h);
lcd.print(":");
int m = gps.time.minute();
if (m < 10) {
lcd.print("0");
}
lcd.print(m);
}
//--- satellites value ---
if (gps.satellites.isUpdated())
{
int sat = int(gps.satellites.value());
lcd.setCursor(6, 0);
if (sat < 10) {
lcd.print(" ");
}
lcd.print(sat);
lcd.setCursor(8, 0);
lcd.print("sat");
}
//--- speed ---
if (gps.speed.isUpdated())
{
int spd = int(gps.speed.kmph());
lcd.setCursor(0, 1);
lcd.print("spd ");
lcd.setCursor(5, 1);
if (spd < 10) {
lcd.print(" ");
//lcd.print(spd);
//lcd.print("Km/h");
} else if (spd < 100) {
lcd.print(" ");
//lcd.print(spd);
//lcd.print("Km/h");
} else {
//lcd.print(spd);
//lcd.print("Km/h");
}
lcd.print(spd);
lcd.print("km/h");
}
//--- altitude ---
if (gps.altitude.isUpdated())
{
int alt = int(gps.altitude.meters());
Serial.println(alt);
lcd.setCursor(0, 2);
lcd.print("alt ");
lcd.setCursor(4, 2);
if (alt <= 0) {
lcd.print("----");
//lcd.print("m");
} else if (alt < 10) {
lcd.print(" ");
lcd.print(alt);
lcd.print("m");
} else if (alt < 100) {
lcd.print(" ");
lcd.print(alt);
lcd.print("m");
} else if (alt < 1000) {
lcd.print(" ");
lcd.print(alt);
lcd.print("m");
} else {
lcd.print(alt);
lcd.print("m");
}
}
//--- course ---
if (gps.course.isUpdated())
{
int dir = gps.course.deg();
lcd.setCursor(17, 3);
if (dir < 10 ) {
lcd.print(" ");
}
else if (dir < 100 ) {
lcd.print(" ");
}
lcd.print(dir);
if ((gps.course.deg()) == 0) {
lcd.setCursor(17, 0);
lcd.print(" ");
lcd.setCursor(17, 1);
lcd.print(" + ");
lcd.setCursor(17, 2);
lcd.print(" ");
}
else if ((gps.course.deg()) < 22.5) {
lcd.setCursor(17, 0);
lcd.print(" * ");
lcd.setCursor(17, 1);
lcd.print(" + ");
lcd.setCursor(17, 2);
lcd.print(" ");
}
else if ((gps.course.deg()) < 67.5) {
lcd.setCursor(17, 0);
lcd.print(" *");
lcd.setCursor(17, 1);
lcd.print(" + ");
lcd.setCursor(17, 2);
lcd.print(" ");
}
else if ((gps.course.deg()) < 112.5) {
lcd.setCursor(17, 0);
lcd.print(" ");
lcd.setCursor(17, 1);
lcd.print(" +*");
lcd.setCursor(17, 2);
lcd.print(" ");
}
else if ((gps.course.deg()) < 151.5) {
lcd.setCursor(17, 0);
lcd.print(" ");
lcd.setCursor(17, 1);
lcd.print(" + ");
lcd.setCursor(17, 2);
lcd.print(" *");
}
else if ((gps.course.deg()) < 202.5) {
lcd.setCursor(17, 0);
lcd.print(" ");
lcd.setCursor(17, 1);
lcd.print(" + ");
lcd.setCursor(17, 2);
lcd.print(" * ");
}
else if ((gps.course.deg()) < 247.5) {
lcd.setCursor(17, 0);
lcd.print(" ");
lcd.setCursor(17, 1);
lcd.print(" + ");
lcd.setCursor(17, 2);
lcd.print("* ");
}
else if ((gps.course.deg()) < 292.5) {
lcd.setCursor(17, 0);
lcd.print(" ");
lcd.setCursor(17, 1);
lcd.print("*+ ");
lcd.setCursor(17, 2);
lcd.print(" ");
}
else if ((gps.course.deg()) < 337.5) {
lcd.setCursor(17, 0);
lcd.print("* ");
lcd.setCursor(17, 1);
lcd.print(" + ");
lcd.setCursor(17, 2);
lcd.print(" ");
}
else {
lcd.setCursor(17, 0);
lcd.print(" * ");
lcd.setCursor(17, 1);
lcd.print(" + ");
lcd.setCursor(17, 2);
lcd.print(" ");
}
}
}
0 件のコメント:
コメントを投稿