2016-09-30 21:14:29 +00:00
|
|
|
#include "SegmentDisplay.h"
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-11-29 19:00:47 +00:00
|
|
|
#define ASCIIUppercaseA 65
|
|
|
|
#define ASCIIUppercaseZ 90
|
|
|
|
|
2016-09-30 21:14:29 +00:00
|
|
|
SegmentDisplay* display;
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-11-29 19:00:47 +00:00
|
|
|
char* text = new char[7];
|
|
|
|
|
|
|
|
|
2016-09-26 21:14:03 +00:00
|
|
|
void setup()
|
2016-09-24 12:12:19 +00:00
|
|
|
{
|
2016-11-29 19:00:47 +00:00
|
|
|
pinMode(2, INPUT_PULLUP);
|
2016-11-27 22:14:17 +00:00
|
|
|
pinMode(A3, INPUT);
|
2016-11-29 19:00:47 +00:00
|
|
|
|
2016-09-30 21:14:29 +00:00
|
|
|
display = new SegmentDisplay();
|
|
|
|
//display->setClockSpeed(4000000UL);
|
2016-11-27 22:14:17 +00:00
|
|
|
display->setClockPin(12);
|
|
|
|
display->setDataPin(11);
|
|
|
|
display->setLatchPin(10);
|
|
|
|
display->setDigits(6);
|
2016-09-30 21:14:29 +00:00
|
|
|
display->begin();
|
2016-11-29 19:00:47 +00:00
|
|
|
|
|
|
|
text[0] = '\0';
|
|
|
|
text[1] = '\0';
|
|
|
|
text[2] = '\0';
|
|
|
|
text[3] = '\0';
|
|
|
|
text[4] = '\0';
|
|
|
|
text[5] = '\0';
|
|
|
|
text[6] = '\0';
|
2016-09-24 12:12:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-27 22:14:17 +00:00
|
|
|
unsigned long currentTime;
|
2016-09-30 21:14:29 +00:00
|
|
|
unsigned long lastCounterTime = 0;
|
|
|
|
uint32_t counter = 0;
|
2016-11-27 22:14:17 +00:00
|
|
|
uint32_t delayValue;
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-11-29 19:00:47 +00:00
|
|
|
bool showChars = true;
|
|
|
|
byte character = ASCIIUppercaseA - 1;
|
|
|
|
|
|
|
|
int buttonValue;
|
|
|
|
bool buttonDown = false;
|
|
|
|
unsigned long lastButtonChange = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-09-26 21:14:03 +00:00
|
|
|
void loop()
|
2016-09-24 12:12:19 +00:00
|
|
|
{
|
2016-11-27 22:14:17 +00:00
|
|
|
currentTime = millis();
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-11-29 19:00:47 +00:00
|
|
|
buttonValue = digitalRead(2);
|
|
|
|
if (buttonValue == LOW)
|
|
|
|
{
|
|
|
|
if (!buttonDown && (currentTime - lastButtonChange) > 50)
|
|
|
|
{
|
|
|
|
buttonDown = true;
|
|
|
|
showChars = !showChars;
|
|
|
|
lastButtonChange = currentTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (buttonDown && (currentTime - lastButtonChange) > 50)
|
|
|
|
{
|
|
|
|
buttonDown = false;
|
|
|
|
lastButtonChange = currentTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showChars)
|
2016-09-24 12:12:19 +00:00
|
|
|
{
|
2016-11-29 19:00:47 +00:00
|
|
|
if (lastCounterTime == 0 || currentTime - lastCounterTime > 250UL)
|
|
|
|
{
|
|
|
|
character++;
|
|
|
|
if (character > ASCIIUppercaseZ)
|
|
|
|
character = ASCIIUppercaseA;
|
|
|
|
|
|
|
|
lastCounterTime = currentTime;
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-11-29 19:00:47 +00:00
|
|
|
delayValue = ((uint32_t)analogRead(A3) * 100);
|
|
|
|
display->setDigitDelayMicroseconds(delayValue);
|
|
|
|
}
|
2016-11-27 22:14:17 +00:00
|
|
|
|
2016-11-29 19:00:47 +00:00
|
|
|
for (byte c = 0; c < 6; c++)
|
|
|
|
{
|
|
|
|
if (character + c > ASCIIUppercaseZ)
|
|
|
|
text[c] = ' ';
|
|
|
|
else
|
|
|
|
text[c] = character + c;
|
|
|
|
}
|
|
|
|
|
|
|
|
display->writeTextLeft(text);
|
2016-09-30 21:14:29 +00:00
|
|
|
}
|
2016-11-29 19:00:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (currentTime - lastCounterTime > 100UL)
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
if (counter > 999999)
|
|
|
|
counter = 0;
|
|
|
|
|
|
|
|
lastCounterTime = currentTime;
|
2016-09-24 12:12:19 +00:00
|
|
|
|
2016-11-29 19:00:47 +00:00
|
|
|
delayValue = ((uint32_t)analogRead(A3) * 100);
|
|
|
|
display->setDigitDelayMicroseconds(delayValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
display->writeNumber(counter);
|
|
|
|
}
|
2016-09-24 12:12:19 +00:00
|
|
|
}
|