Commit dbe56f89 authored by Malý Jiří's avatar Malý Jiří 😵
Browse files

Naming and sorting constants

parent 46135dd6
#include "funshield.h"
constexpr int buttonPins[]{button1_pin, button2_pin, button3_pin};
constexpr int buttonPinsCount = sizeof(buttonPins) / sizeof(buttonPins[0]);
constexpr int displayDigits = 4;
int currentDigit;
constexpr int maxThrows = 9;
constexpr int ScrollingPeriod =500;
static int power(int base, int exponent)
{
int result = 1;
......@@ -17,9 +10,14 @@ static int power(int base, int exponent)
return result;
}
int maxNum = power(10, displayDigits);
byte segmentMap[] = {
#pragma region ArduinoConstants
constexpr int buttonPins[]{button1_pin, button2_pin, button3_pin};
constexpr int buttonPinsCount = sizeof(buttonPins) / sizeof(buttonPins[0]);
constexpr int displayDigits = 4;
constexpr int ScrollingPeriod =500;
const int seeds=3;
constexpr byte segmentMap[] = {
0xC0, // 0 0b11000000
0xF9, // 1 0b11111001
0xA4, // 2 0b10100100
......@@ -32,6 +30,19 @@ byte segmentMap[] = {
0x90, // 9 0b10010000
0xA1 // d 0b10100001
};
byte positionMap[] = {
0x08, // 1 0b00001000
0x04, // 2 0b00000100
0x02, // 3 0b00000010
0x01, // 4 0b00000001
};
const int maxNum = power(10, displayDigits);
#pragma endregion
#pragma region Dicetray constants
constexpr int maxThrows = 9;
constexpr int dice[] = {4, 6, 8, 10, 20, 100};
constexpr int diceLenght = sizeof(dice) / sizeof(dice[0]);
byte letters[] = {
0xAF, // R 0b10101111
0xA3, // o 0b10100011
......@@ -42,14 +53,9 @@ byte letters[] = {
0x82 // g 0b10000010
};
constexpr int lettersLenght = sizeof(letters) / sizeof(letters[0]);
byte positionMap[] = {
0x08, // 1 0b00001000
0x04, // 2 0b00000100
0x02, // 3 0b00000010
0x01, // 4 0b00000001
};
int dice[] = {4, 6, 8, 10, 20, 100};
constexpr int diceLenght = sizeof(dice) / sizeof(dice[0]);
#pragma endregion
int currentDigit;
static void BetterShiftOut(byte what, int where)
{
......@@ -58,7 +64,7 @@ static void BetterShiftOut(byte what, int where)
shiftOut(data_pin, clock_pin, MSBFIRST, positionMap[where]);
digitalWrite(latch_pin, OFF);
}
const int seeds=3;
class randomizer
{
......@@ -117,7 +123,7 @@ class dicetray
}
else if (running == state)
{
BetterShiftOut(letters[(Digit + offset) % lettersLenght], (Digit - 3) * (-1));
BetterShiftOut(letters[(Digit + offset) % lettersLenght], (Digit - (displayDigits-1)) * (-1));
if (time + ScrollingPeriod < millis())
{
time = millis();
......@@ -211,7 +217,7 @@ class dicetray
}
void setup()
{
state = 2;
state = config;
diceType = 0;
throws = 1;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment