right so when i upload this code:
#include <LiquidCrystal.h>
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
#define ledPin 13 // LED connected to digital pin 13 // button on pin 4
int val;
int value = LOW; // previous value of the LED
int buttonState; // variable to store button state
int lastButtonState; // variable to store last button state
int blinking; // condition for blinking - timer is timing
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
void setup() {
pinMode(ledPin, OUTPUT); // sets the digital pin as output
// turn on pullup resistors. Wire button so that press shorts pin to ground.
pinMode(4, OUTPUT);
// limpa o ecra
lcd.clear();
// setCursor(coluna [0-15], linha [0-1])
}
void loop(){
val == analogRead(1);
lcd.setCursor(0,0);
lcd.print("StopWatch");
lcd.setCursor(0,11);
lcd.print(val);
lcd.setCursor(0,1);
lcd.print("Took");
lcd.setCursor(11,1);
lcd.print("Sec's");
lcd.setCursor(5,1);
// check for button press
buttonState = analogRead(0); // read the button state and store
if (buttonState < val && lastButtonState > val && blinking == false){ // check for a high to low transition
// if true then found a new button press while clock is not running - start the clock
startTime = millis(); // store the start time
blinking = true; // turn on blinking while timing
delay(5); // short delay to debounce switch
lastButtonState = buttonState; // store buttonState in lastButtonState, to compare next time
}
else if (buttonState < val && lastButtonState > val && blinking == true){ // check for a high to low transition
// if true then found a new button press while clock is running - stop the clock and report
elapsedTime = millis() - startTime; // store elapsed time
blinking = false; // turn off blinking, all done timing
lastButtonState = buttonState; // store buttonState in lastButtonState, to compare next time
// routine to report elapsed time
lcd.print( (int)(elapsedTime / 1000L)); // divide by 1000 to convert to seconds - then cast to an int to print
lcd.print("."); // print decimal point
// use modulo operator to get fractional part of time
fractional = (int)(elapsedTime % 1000L);
// pad in leading zeros - wouldn't it be nice if
// Arduino language had a flag for this?
if (fractional == 0){
lcd.print("000"); // add three zero's
} else if (fractional < 10) // if fractional < 10 the 0 is ignored giving a wrong time, so add the zeros
lcd.print("00"); // add two zeros
else if (fractional < 100)
lcd.print("0"); // add one zero
lcd.print(fractional); // print fractional part of time
}
else{
lastButtonState = buttonState; // store buttonState in lastButtonState, to compare next time
}
// blink routine - blink the LED while timing
// check to see if it's time to blink the LED; that is, the difference
// between the current time and last time we blinked the LED is larger than
// the interval at which we want to blink the LED.
if ( (millis() - previousMillis > interval) ) {
if (blinking == true){
previousMillis = millis(); // remember the last time we blinked the LED
// if the LED is off turn it on and vice-versa.
if (value == LOW)
value = HIGH;
else
value = LOW;
digitalWrite(ledPin, value);
}
else{
digitalWrite(ledPin, LOW); // turn off LED when not blinking
}
}
}
i get this error:
Binary sketch size: 2914 bytes (of a 14336 byte maximum)
avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51
whats up with this?
thanks