Webca:
I still cant get it to work...
Here is the code:
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define ledPin 13 // LED connected to digital pin 13
#define buttonPin 9 // button on pin 4
int value = LOW; // previous value of the LED
int buttonState; // variable to store button state
int lastButtonState; // variable to store last button state
long interval = 100; // blink interval - change to suit
long previousMillis = 0; // variable to store last time LED was updated
long startTime ; // start time for stop watch
long elapsedTime ; // elapsed time for stop watch
int fractional; // variable used to store fractional part of time
boolean test = false;
boolean start = false;
byte lastbuttonState2 = 0; // new global variable
byte buttonState1 = 0;
byte buttonState2 = 0;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 4);
// Print a message to the LCD.
lcd.print("Test");
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(buttonPin, INPUT); // not really necessary, pins default to INPUT anyway
digitalWrite(buttonPin, HIGH); // turn on pullup resistors. Wire button so that press shorts pin to ground.
}
void loop()
{
buttonState1 = digitalRead(buttonPin);
delay(20);
buttonState2 = digitalRead(buttonPin);
if(buttonState1 == buttonState2) {
if(buttonState2 == HIGH){
start = true;
startTime = millis();
lastButtonState = buttonState2;
}
if(start == true){
elapsedTime = millis() - startTime; // store elapsed time
lastButtonState = buttonState; // store buttonState in lastButtonState, to compare next time
lcd.setCursor(0,2);
lcd.print(" ");
// routine to report elapsed time
lcd.print( (int)(elapsedTime / 1000UL)); // divide by 1000 to convert to seconds - then cast to an int to print
lcd.print(".");
fractional = (int)(elapsedTime % 1000UL);
if (fractional == 0)
lcd.print("000");
else if (fractional < 10)
lcd.print("00");
else if (fractional < 100)
lcd.print("0");
lcd.print(fractional); // print fractional part of time
}
if(test == true){
if(buttonState1 == HIGH)
start == true;
else;{}
}
}
}
I guess my hint wasn't easy enough to understand. It's only 3 new lines you need to add, along with any brackets.