You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm creating gps +speed meter device and i want to use buttons to change things on display. When button is clicked device get into bootloop and only thing I can do is reset device. Is there any possibility that interrupts will work with buttons or should i measure speed without interrupts?
Here is my code:
#include <M5Core2.h>
#include <TinyGPS++.h>
#define PIN 21
float start, finished;
float elapsed;
float circMetric=2.093; // wheel circumference (in meters)
float circImperial; // using 1 kilometer = 0.621371192 miles
float speedk, speedm; // holds calculated speed vales in metric and imperial
// A sample NMEA stream.
const char *gpsStream =
"$GPRMC,045103.000,A,3014.1984,N,09749.2872,W,0.67,161.46,030913,,,A*7C\r\n";
// The TinyGPS++ object
TinyGPSPlus gps;
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (Serial2.available() > 0)
gps.encode(Serial2.read());
} while (millis() - start < ms);
M5.Lcd.clear();
}
void displayInfo()
{
M5.Lcd.setCursor(0, 40, 4);
M5.Lcd.print(F("Latitude: "));
if (gps.location.isValid())
{
M5.Lcd.print(gps.location.lat(), 6);
}
else
{
M5.Lcd.print(F("INVALID"));
}
M5.Lcd.println();
M5.Lcd.print(F("Longitude: "));
if (gps.location.isValid())
{
M5.Lcd.print(gps.location.lng(), 6);
}
else
{
M5.Lcd.print(F("INVALID"));
}
M5.Lcd.println();
M5.Lcd.print(F("Altitude: "));
if (gps.altitude.isValid())
{
M5.Lcd.print(gps.altitude.meters());
}
else
{
M5.Lcd.print(F("INVALID"));
}
M5.Lcd.println();
M5.Lcd.print(F("Speed sensor: "));
M5.Lcd.print(int(speedk));
M5.Lcd.println();
M5.Lcd.print(F("Speed: "));
if (gps.speed.isValid())
{
M5.Lcd.print(gps.speed.kmph());
}
else
{
M5.Lcd.print(F("INVALID"));
}
}
void speedCalc()
{
//Function called by the interrupt
if((millis()-start)>100) // 100 millisec debounce
{
//calculate elapsed
elapsed=millis()-start;
//reset start
start=millis();
//calculate speed in km/h
speedk=(3600*circMetric)/elapsed;
}
}
void setup()
{
M5.begin(true,true,true,false);
Serial2.begin(9600, SERIAL_8N1, 13, 14);
attachInterrupt(digitalPinToInterrupt(PIN), speedCalc, FALLING);
start=millis();
}
void loop()
{
M5.update();
if(M5.BtnC.wasPressed())
{
M5.Lcd.print(F("Change"));
}
smartDelay(1000);
displayInfo();
}
The text was updated successfully, but these errors were encountered:
I'm creating gps +speed meter device and i want to use buttons to change things on display. When button is clicked device get into bootloop and only thing I can do is reset device. Is there any possibility that interrupts will work with buttons or should i measure speed without interrupts?
Here is my code:
The text was updated successfully, but these errors were encountered: