Thank you for the input Here is the code embeded.
//Navigational stopwatch
//by Mats
/*********************************************************************
Adafruit library for Monochrome OLEDs based on SSD1306 drivers
https://github.com/adafruit/Adafruit_SSD1306
Adafruit GFX library:
https://github.com/adafruit/Adafruit-GFX-Library
*********************************************************************/
#include<ButtonV2.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
#define numOfButtons 3
ButtonV2 buttonArray[numOfButtons];
#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
//------------------------------------------------------ eo Adafruit header
//define the four timer states.
#define WAITING 0 // waiting to start
#define TIMERONE 1 // timer one running
#define NMDIST 2 // nautical miles traveled
#define FINISHED 3 // timer complete
const long minute = 60000; // 60000 milliseconds in a minute
const long nautical = 10; //10 cabels in one nauicle
const int resetPin = 2;
const int startPin = 3;
const int choosePin = 4;
//const int ledPin = 13; // the number of the LED pin
const byte ButtonPins[numOfButtons] = {2, 3, 4};
long startTime = 0;
long timeOne = 0;
long navdist = 0;
int timer = WAITING; // timer state. Initially waiting for first button press
int reset = 0; // reset button state
int start = 0; // main button state
long kabler, nm;
void setup() {
pinMode(startPin, INPUT); //init button pin to input
pinMode(resetPin, INPUT); //init reset pin to input
pinMode(choosePin, INPUT); //init choose pin to input
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3c
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(10,0);
printDigits(0);
display.display();
delay(2000);
// Clear the buffer.
display.clearDisplay();
// draw a single pixel
display.drawPixel(10, 10, WHITE);
// Show the display buffer on the hardware.
// NOTE: You _must_ call display after making any drawing commands
// to make them visible on the display hardware!
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
//-------- main loop -------
switch ( timer){
case WAITING: // initial state - waiting for first button press.
display.clearDisplay();
display.setCursor(10,00);
printDigits(0);
display.display(); // display screen showing 00:00s
start = digitalRead(startPin);
if(start){ // start is pressed.
timer = TIMERONE; // start the first timer
startTime = millis();//read the time the button is pressed.
while (digitalRead(startPin)){
//--- wait for button to be released.
}
}
break;
case TIMERONE: //running first timer
timeOne = millis();
start = digitalRead(startPin);
reset = digitalRead(resetPin);
display.clearDisplay();
display.setCursor(10,00);
printDigits(timeOne - startTime);
display.display();
//-----------------------------------
if(reset){ //reset button was pressed. Clear screeen and start again
timer = WAITING;
while (digitalRead(resetPin)){
//--- wait for reset button to be released.
}
}
//------------------------------------
if(start){ // start was pressed
timer = NMDIST; // start lengde
distance = natical(); //record the distance from the time of the first timer
while (digitalRead(startPin)){
//--- wait for button to be released.
}
}
break;
case NMDIST: //running first timer
distance = nautical((18 * (timeOne - startTime))/ 60);
//distance = (18 * (timeOne - startTime))/ 60; //formula for calculating distance (speed * Time)/ 60
start = digitalRead(startPin);
reset = digitalRead(resetPin);
display.clearDisplay();
display.setCursor(10,00);
printDigits(timeOne - startTime); // display the first time
display.setCursor(10,32);
printDigits(distance); // display the distance on the second line
display.display();
//------------------------------------
if(reset){ //reset button was pressed. Clear screeen and start again.32w
timer = WAITING;
while (digitalRead(resetPin)){
//--- wait for reset button to be released.
}
}
//------------------------------------
if(start){ // button was pressed
timer = FINISHED; // start the second timer
while (digitalRead(startPin)){
//--- wait for button to be released.
}
}
break;
case FINISHED: //running first timer
reset = digitalRead(resetPin);
if(reset){ //reset button was pressed. Clear screeen and start again
display.clearDisplay();
display.setCursor(10,0);
printDigits(0);
display.display();
timer = WAITING;
while (digitalRead(resetPin)){
//--- wait for reset button to be released.
}
}
break;
} // eo switch
}// eo void loop
void printDigits(long timeInMillis){
// convert the time from milliseconds to four digit SS:HH
// seconds and hundredths and display at current cursor position
int seconds;
int hundredths;
seconds = timeInMillis /1000;
seconds = seconds % 60; // seconds never more than 60
hundredths = (timeInMillis % 1000)/10;
if (seconds <10){ // print leading zero if necessary
display.print("0");
}
display.print(seconds);
display.print(":");
if (hundredths <10){ //print leading zero if necessary
display.print("0");
}
display.print(hundredths);
display.print("s");
//display.display();
}
void printNumbers(long distanceNautical) {
int nautical;
int cabel;
nautical = cabel * 10;
cabel = cabel % 1; //one cabel can't be bigger than 1, it is allways 0,something example 0,1 0,5 and so forth
}