first Functions
This commit is contained in:
148
src/main.cpp
Normal file
148
src/main.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
#include <Arduino.h>
|
||||
#include <TM1637Display.h>
|
||||
|
||||
// Module connection pins (Digital Pins)
|
||||
#define CLK 2
|
||||
#define DIO_GOF 3
|
||||
#define DIO_MIL 4
|
||||
#define DIO_KGG 5
|
||||
|
||||
enum Parties
|
||||
{
|
||||
NONE,
|
||||
GOF,
|
||||
MILIZ,
|
||||
KGG
|
||||
};
|
||||
|
||||
TM1637Display disp_GOF(CLK, DIO_GOF);
|
||||
TM1637Display disp_MIL(CLK, DIO_MIL);
|
||||
TM1637Display disp_KGG(CLK, DIO_KGG);
|
||||
|
||||
Parties activeParty = NONE;
|
||||
|
||||
uint32_t Count_GOF = 0;
|
||||
uint32_t Count_MILIZ = 0;
|
||||
uint32_t Count_KGG = 0;
|
||||
uint8_t KGG_dot = 0;
|
||||
uint8_t GOF_dot = 0;
|
||||
uint8_t MIL_dot = 0;
|
||||
|
||||
void setBrightness()
|
||||
{
|
||||
|
||||
switch (activeParty)
|
||||
{
|
||||
case GOF:
|
||||
disp_GOF.setBrightness(7);
|
||||
disp_MIL.setBrightness(0);
|
||||
disp_KGG.setBrightness(0);
|
||||
break;
|
||||
|
||||
case MILIZ:
|
||||
disp_GOF.setBrightness(0);
|
||||
disp_MIL.setBrightness(7);
|
||||
disp_KGG.setBrightness(0);
|
||||
break;
|
||||
|
||||
case KGG:
|
||||
disp_GOF.setBrightness(0);
|
||||
disp_MIL.setBrightness(0);
|
||||
disp_KGG.setBrightness(7);
|
||||
break;
|
||||
|
||||
case NONE:
|
||||
default:
|
||||
disp_GOF.setBrightness(0);
|
||||
disp_MIL.setBrightness(0);
|
||||
disp_KGG.setBrightness(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void tickCounter()
|
||||
{
|
||||
static boolean tick_flag = false;
|
||||
if (millis() % 1000 > 500)
|
||||
{
|
||||
if (!tick_flag)
|
||||
{
|
||||
|
||||
switch (activeParty)
|
||||
{
|
||||
case GOF:
|
||||
Count_GOF++;
|
||||
GOF_dot = 0x50;
|
||||
break;
|
||||
|
||||
case MILIZ:
|
||||
Count_MILIZ++;
|
||||
MIL_dot = 0x50;
|
||||
break;
|
||||
|
||||
case KGG:
|
||||
Count_KGG++;
|
||||
KGG_dot = 0x50;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
tick_flag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
tick_flag = false;
|
||||
KGG_dot = 0x40;
|
||||
MIL_dot = 0x40;
|
||||
GOF_dot = 0x40;
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
tickCounter();
|
||||
setBrightness();
|
||||
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
char input = Serial.read();
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case 'n':
|
||||
activeParty = NONE;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
activeParty = GOF;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
activeParty = KGG;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
activeParty = MILIZ;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int temp;
|
||||
|
||||
temp = Count_GOF / 3600 * 100 + (Count_GOF / 60) % 60;
|
||||
disp_GOF.showNumberDecEx(temp / 60, GOF_dot, true, 4, 0);
|
||||
temp = Count_MILIZ / 3600 * 100 + (Count_MILIZ / 60) % 60;
|
||||
disp_MIL.showNumberDecEx(temp, MIL_dot, true, 4, 0);
|
||||
temp = Count_KGG / 3600 * 100 + (Count_KGG / 60) % 60;
|
||||
disp_KGG.showNumberDecEx(temp, KGG_dot, true, 4, 0);
|
||||
}
|
Reference in New Issue
Block a user