Oscar Seo
Published © GPL3+

Simple Lap Counter for Swimming Maniac (Waterproof)

It is a rechargeable waterproof lap counter that does not use a water proof bag separately.

EasyFull instructions provided3 hours1,390
Simple Lap Counter for Swimming Maniac (Waterproof)

Things used in this project

Hardware components

Magconn Developer Kit
×1
Arduino Nano R3
Arduino Nano R3
×1
USB Li-Po Battery Charger PCBA
×1
Li-Po Battery 900mAh
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics

Schematic dowtg5nte3

Code

Lap counter

Arduino
const byte numeral[10] = {
  //ABCDEFG dp//
  B11111100,  //0
  B01100000,  //1
  B11011010,  //2
  B11110010,  //3
  B01100110,  //4
  B10110110,  //5
  B00111110,  //6
  B11100000,  //7
  B11111110,  //8
  B11100110,  //9
};

// dp, G, F, E, D, C, B, A
const int segmentPins[8] = { 9,8,7,6,5,4,3,2 };
const int nbrDigits = 2;
const int digitPins[nbrDigits] = { 12,13 };
const int buttonPin = 11;
int buttonState;             // the current reading from the input pin
int lastButtonState = HIGH;   // the previous reading from the input pin
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers
int value = -1;



void setup() 
{
  for(int i=0; i<8; i++)
  {
    pinMode(segmentPins[i], OUTPUT);    
  }
  for(int i=0; i<nbrDigits; i++)
  {
    pinMode(digitPins[i], OUTPUT);  
    digitalWrite(digitPins[i], 1);   
  }
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);   //   
}



void loop() 
{
  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) { // reset the debouncing timer
    lastDebounceTime = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;

      if (buttonState == HIGH) {
        value = value + 1;
      }
    }
  }
  lastButtonState = reading;  
  showNumber(value);
}



void showNumber(int number)
{
  if(number == 0)
    showDigit(0, nbrDigits-1);
    else
    {
      for(int digit = nbrDigits-1; digit>=0; digit--)
      {
        if (number>0)
        {
          showDigit(number%10, digit);
          number = number/10;
        }
      }
    }
}



void  showDigit(int number, int digit)
{
  //boolean   isBitSet;  
  digitalWrite(digitPins[digit],0);  //1
  for (int segment = 1; segment <8 ; segment++) //segment A ~ dp  
  {
    boolean isBitSet = bitRead(numeral[number], segment);   //byte numeral[number] segment  
    digitalWrite(segmentPins[segment], isBitSet);
    }
    //isBitSet = !isBitSet
    delay(5);
    digitalWrite(digitPins[digit], 1);
  }
  

Credits

Oscar Seo

Oscar Seo

1 project • 6 followers
I am a H / W engineer and manager at Magconn Inc. Try the "magconn connector" for connectivity convenience.
Contact

Comments