Automatisk stoppur (5 / 5 steg)
Steg 5: Arduino kod
Denna stoppur Visa tiden i formatet timmar: minuter: sekunder: millisekunder
Nedan är den koden du behöver "verifiera" i Arduino 1.6.6 och ladda upp i arduino simuleringen
#include
CONST byte interruptPin2 = 2;
CONST byte interruptPin3 = 3;
int staten.
int antal;
int första;
int minut.
int sekunder.
int timmar;
LiquidCrystal lcd(12,11,7,6,5,4);
void setup() {
pinMode(interruptPin2,INPUT_PULLUP);
pinMode(interruptPin3,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin2), start, faller);
attachInterrupt(digitalPinToInterrupt(interruptPin3), stop1, faller);
Ange den LCD antal kolumner och rader:
LCD.BEGIN (16, 2);
lcd.setCursor(1,0);
LCD.Print ("tid:");
lcd.setCursor(3,1);
LCD.Print(":");
lcd.setCursor(7,1);
LCD.Print(":");
lcd.setCursor(11,1);
LCD.Print(":");
}
void loop() {
initial=Millis();
sekunder = 0; minut = 0; timmar = 0;
While(State) {
count=(int)((Millis()-initial));
IF(count>999) {
inledande += 1000;
sekunder ++;
IF(seconds>59) {
sekunder = 00.
lcd.setCursor(9,1);
LCD.Print("");
minut ++;
IF(Minute>59) {
minut = 0;
lcd.setCursor(5,1);
LCD.Print("");
timmar ++;
}
}
}
lcd.setCursor(0,1);
LCD.Print(hours);
lcd.setCursor(4,1);
LCD.Print(Minute);
lcd.setCursor(8,1);
LCD.Print(seconds);
lcd.setCursor(12,1);
LCD.Print(Count);
}}
void start() {
State = 1;
}
void stop1() {
State = 0;
}