Help with a project

Doing a sketch to show a warning led at around 5mph, and want it to stay on until a restart / button is pressed, im a novice and trying

next step i am trying to do is if a button is pressed then re-enable loop at this point

if (kmh > 7) // // output to pin 10
digitalWrite( WARNING_LED_0, LOW );

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); ;    

#include <NMEAGPS.h>
#include <NeoSWSerial.h>
NeoSWSerial gpsSerial(6,7);  // gps on pins 6,7
NMEAGPS gps;

const int WARNING_LED_0 = 10;   // warning led on pin 10  



void setup()
{
  pinMode( WARNING_LED_0, OUTPUT );
  

  lcd.begin(16, 2);
  lcd.clear();
  lcd.print( F("gps warning) );  
  gpsSerial.begin(9600);
  delay(2000);
  lcd.clear(); 
}

void printTime( NeoGPS::time_t & time )
{
  if (time.hours < 10)
    lcd.print( '0' );
  lcd.print( time.hours );
  if (time.minutes < 10)
    lcd.print( '0' );
  lcd.print( time.minutes );
  if (time.seconds < 10)
    lcd.print( '0' );
  lcd.print( time.seconds );

} // printTime


void displayGPS( gps_fix & fix )
{
  int kmh = 0;

  // Print speed
  lcd.setCursor(0,0);
  if (fix.valid.speed && (fix.spd.whole > 5)) {
    kmh = (fix.spd.whole * 185) / 100;
  }
  lcd.print( kmh );
  lcd.print( F(" km/h      ") );



   if (kmh > 7)    //             // output to pin 10 
    digitalWrite( WARNING_LED_0, LOW ); 
 


    // Print time
  if (fix.valid.time) {
    printTime( fix.dateTime );
  }
} // displayGPS

void loop()
{
  while (gps.available( gpsSerial )) {  // if there is data coming from the GPS shield
    gps_fix fix = gps.read();           // get the complete fix structure
    displayGPS( fix );                  // Show pieces of the fix on the LCD
  }
}

Ok… you set the warning light pin LOW when the speed is greater than 5 and speed * 185/100 is greater than 7. That pin will stay LOW until you change it (or reset).

I think the only thing you have to add is some code in loop() to detect when your button is pressed. When that button is pressed, set the warning light output pin to HIGH.

ktnch:
Doing a sketch to show a warning led at around 5mph,

if (kmh > 7) //

Most of us here have heard of kilometres so if you want to work in kmh why mention mph?

IIRC 5mph = 8kmh so that I am a bit confused by the numbers you have chosen.

...R

Thank you johnwasser

so define pin 1 as enable sketch ?

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); ;

#include <NMEAGPS.h>
#include <NeoSWSerial.h>
NeoSWSerial gpsSerial(6,7); // gps on pins 6,7
NMEAGPS gps;

const int WARNING_LED_0 = 10; // warning led on pin 10
const int buttonPin = 1

ktnch:
so define pin 1 as enable sketch ?

What Arduino are you using?

Pins 0 and 1 are usually used by Serial and if so it is better not to use them for anything else.

...R

Its the nano matey

ktnch:
Its the nano matey

How does that differ from a regular nano ? :slight_smile:

...R

lol

Robin2:
How does that differ from a regular nano ? :slight_smile:

...R

The eyepatch and pegleg are a dead giveaway.

BJHenry:
The eyepatch and pegleg are a dead giveaway.

That would be a nano pirate.