GithubHelp home page GithubHelp logo

Comments (2)

JasonPittenger avatar JasonPittenger commented on August 16, 2024

gps.encode() processes the data one byte at a time.
You really don't want to be testing the return for every byte.

The best bet is to separate the serial reading & gps encoding from everything else.
Also, don't use delay(10);
This stops all processing for 10 milliseconds.
Instead, use millis().
This will cause the loop to continue running, and reading the GPS data.
Then every 10 milliseconds, it will jump into the code that actually updates the LEDs.

Try this. (NOTE: I did not build or run this, so it might have errors. But it should be at least 95% correct)

loop()
{
	uint16_t GPSbytesAvailable;
	uint32_t LED_Update;
	uint8_t BlueCounter = 1;

	GPSbytesAvailable = GPS_Serial.available();
	while(GPSbytesAvailable--)
	{
		gps.encode(GPS_Serial.read());
	}
	
	if((millis() - LED_Update) >= 10))
	{
		LED_Update = millis();
		if (gps.speed.isValid()) 
		{
			BlueCounter = 1;
			age = gps.speed.age();
			Serial.print("Speed: ");
			Serial.print(gps.speed.mph());
			Serial.println(" mph");
	
			static uint8_t hue = 0; // Starting hue value
			static uint8_t wavePosition = 0; // Current position of the wave
	
			// Calculate color for each LED based on wave position
			for (int i = 0; i < NUM_LEDS; i++) 
			{
				uint8_t color = sin8(i * 8 + wavePosition); // Use sine function for color intensity
				leds[i] = CHSV(hue, 255, color); // Set color based on hue and intensity
			}
			wavePosition++; // Increment wave position for the next frame
		}
		else
		{
			Serial.println("No speed data");
	
			// Slowly pulses blue when "No speed data" is presented.
			uint8_t blue = 0; // Blue color value
			if(BlueCounter)
			{
				blue = sin8(BlueCounter);
				fill_solid(leds, NUM_LEDS, CRGB(0, 0, blue));
				BlueCounter++
			}
			else
			{
				// Set all LEDs to off
				fill_solid(leds, NUM_LEDS, CRGB(0, 0, 0)); // Off
			}
		}
		FastLED.show();
	}
}

from tinygpsplus.

svdrummer avatar svdrummer commented on August 16, 2024

If this is complete, please close it

from tinygpsplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.