Ciao a tutti, ho un GPS che mi rilascia un dato heading (head) in gradi e vorrei trasformarlo in una lettura sul display in lettere. pensavo di dividere i 360 gradi della bussola in 16 settori e riportarli sul display convertiti in lettere, ad esempio N Ne nE E
ho provato in vari modi ma non sono riuscito, ho provato ad usare char ma non so se sia corretto, non lo so usare.
adesso ho lasciato il codice con le // nelle parti aggiunte dove ho fatto le prove.
per favore potete aiutarmi a capire dove sbaglio?
il dato heading e tutto il GPS funziona benissimo se lo lascio così com'è adesso e carico lo sketch, nelle prove che ho fatto cercando di trasformare i gradi head in settori descritti con una lettera è sempre rimasto a 0.0
allego il codice e vi ringrazio se avrete voglia di darmi una mano.
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
#include <NMEAGPS.h>
#include <NeoSWSerial.h>
const int cs_sd = 2;
#define I2C_ADDRESS 0x3C
#define RST_PIN -1
SSD1306AsciiWire oled;
NMEAGPS gps;
gps_fix fix;
File myFile;
float odo;
float Speed;
float alt;
float Sat;
float Dist;
float maxs = 0;
float Am = 0;
float head;
//char(N);//aggiunta
//char(Ne);// aggiunta
NeoGPS::Location_t lastLoc, base;
bool stScan = true;
bool lastLocOK = false;
static const int RXPin = 5, TXPin = 4;
static const uint32_t GPSBaud = 9600;
NeoSWSerial gpsPort(RXPin, TXPin);
const int SHOW_INTERVAL = 1;
const int INITIAL_SHOW = (2 * SHOW_INTERVAL) - 1;
int show = INITIAL_SHOW;
const int LED_PIN = 3;
const float SPEED_LIMIT = 0.1; // speed limit value
void setup() {
pinMode (LED_PIN, OUTPUT);
Serial.begin(9600);
gpsPort.begin(GPSBaud);
Wire.begin();
oled.begin(&SH1106_128x64, I2C_ADDRESS);
oled.setFont(ZevvPeep8x16);
oled.clear();
oled.setCursor(23, 2);
oled.println("LOGGER GPS");
delay(2000);
oled.clear();
if (!SD.begin(cs_sd)) {
oled.clear();
oled.setCursor(60, 2);
oled.print("SD");
delay(10000);
oled.clear();
return;
}
oled.setCursor(60, 2);
oled.print("OK");
delay(2000);
oled.clear();
File data = SD.open("log.csv", FILE_WRITE);
data.println("");
data.println("D H La Lo A Am Km D V" );
data.close();
}
void loop() {
if (gps.available( gpsPort )) {
gps_fix fix = gps.read();
show = (show + 1) % SHOW_INTERVAL;
if ( Speed > maxs)
maxs = Speed;
if (fix.valid.heading )
head = (fix.heading() );
//{if ( (head >= 270 && head <= 90));//aggiunta
// head = char (N);//aggiunta
//if ( (head >= 90 && head <= 270));//aggiunta
//head = char (Ne);}// aggiunta
if (fix.valid.satellites )
Sat = (fix.satellites );
if (fix.valid.altitude)
alt = (fix.altitude ());
if ( alt > Am)
Am = alt;
if (fix.valid.speed && (fix.speed_kph() > SPEED_LIMIT)) {
digitalWrite( LED_PIN, HIGH );
} else {
digitalWrite( LED_PIN, LOW );
}
if (fix.valid.location) {
if (lastLocOK) {
odo += fix.location.DistanceKm( lastLoc );
Speed = (fix.speed_kph());
}
lastLoc = fix.location;
lastLocOK = true;
if (stScan) {
stScan = false;
base = fix.location;
} else {
Dist = ( fix.location.DistanceKm( base ) );
}
}
if (show == 0) {
#define MAX_CHARS 24
char displayBufffer[MAX_CHARS];
oled.setCursor(0, 0);
snprintf(displayBufffer, MAX_CHARS, "Km:%2d.%1d", (int)odo, (int)(odo * 100) % 100);
oled.println(displayBufffer);
oled.setCursor(65, 0);
snprintf(displayBufffer, MAX_CHARS, "Di:%2d.%1d", (int)Dist, (int)(Dist * 100) % 100);
oled.println(displayBufffer);
snprintf(displayBufffer, MAX_CHARS, "Ve:%2d.%1d", (int)Speed, (int)(Speed * 100) % 100);
oled.println(displayBufffer);
oled.setCursor(65, 2);
snprintf(displayBufffer, MAX_CHARS, "Vm:%2d.%1d", (int)maxs, (int)(maxs * 100) % 100);
oled.println(displayBufffer);
snprintf(displayBufffer, MAX_CHARS, "Al:%2d.%1d", (int)alt, (int)(alt * 100) % 100);
oled.println(displayBufffer);
oled.setCursor(65, 4);
snprintf(displayBufffer, MAX_CHARS, "Am:%2d.%1d", (int)Am, (int)(Am * 100) % 100);
oled.println(displayBufffer);
snprintf(displayBufffer, MAX_CHARS, "Sa:%1d", (int)Sat, (int)(Sat * 100) % 100);
oled.println(displayBufffer);
oled.setCursor(65, 6);
snprintf(displayBufffer, MAX_CHARS, "He:%2d.%1d", (int)head, (int)(head * 100) % 100);
oled.println(displayBufffer);
}
if (fix.dateTime);
String Temps = String(fix.dateTime.hours ) + (":") + (fix.dateTime.minutes);
String Date = String(fix.dateTime.day ) + ("/") + (fix.dateTime.month);
File data = SD.open("log.csv", FILE_WRITE);
data.println(Date + (" ") + Temps + (" ") + String(fix.latitude(), 6) + (" ") + String(fix.longitude(), 6) + (" ") + (alt) + (" ") + (Am) + (" ") + (odo) + (" ") + (Dist) + (" ") + (Speed));
data.close();
}
}