-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anything inside void loop if statement does not work...WHYYYY? #121
Comments
gps.encode() processes the data one byte at a time. The best bet is to separate the serial reading & gps encoding from everything else. Try this. (NOTE: I did not build or run this, so it might have errors. But it should be at least 95% correct)
|
If this is complete, please close it |
Below is my code. The code is suppose to record speed (mph) and print it to the serial monitor using an arduino uno. Also, using the fastLED library, 50 leds will do a red wave. This code works ONLY when it is outside of the if statement "if (gps.encode(gpsSerial.read())) {". When the code is pasted inside, the led code works but very very slow. The red wave happens at 1/100th of real time. Is this a hardware issue? A bug in my code? I have no idea? Please help!
//library for GPS
#include <TinyGPS++.h>
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
//Library for LED
#include <FastLED.h>
// Set the LED parameters
#define LED_PIN 3
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 50
float topSpeed = 50;
CRGB leds[NUM_LEDS];
SoftwareSerial gpsSerial(8,9); //rx => pin 9 , tx => pin 8
TinyGPSPlus gps;
float lattitude,longitude;
float speed;
unsigned long age;
void setup() {
gpsSerial.begin(9600);
Serial.begin(9600);
// Initialize the LED strip
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
// Set the brightness of the LED strip
FastLED.setBrightness(150);
}
void loop() {
while (gpsSerial.available()) {
if (gps.encode(gpsSerial.read())) {
if (gps.speed.isValid()) {
speed = gps.speed.mph();
age = gps.speed.age();
Serial.print("Speed: ");
Serial.print(speed);
Serial.println(" mph");
//*******************************Led functions inside
static uint8_t hue = 0; // Starting hue value
static uint8_t wavePosition = 0; // Current position of the wave
}
}
}
The text was updated successfully, but these errors were encountered: