Commit 0d8a9a5a authored by Arduino Enigma's avatar Arduino Enigma

Update Board100x9x13.ino

parent 2f9c3371
......@@ -32,7 +32,9 @@ char OneFrame[12] = {'+', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 0};
// 5: decrement a digit (0..9) do not display 0
// A: write to A arrays (LED and VALUE commands not important)
// B: write to B arrays (LED and VALUE commands not important)
// C: copy array (B to A if VALUE is 0, A to B otherwise)
// D: set delay (LEDTimerValues)
// E: set fixed brigthness (FixedFade)
// F: flip A and B arrays (LED and VALUE commands not important)
// +0000000FF6 // this board, set onboard D13 LED on
......@@ -181,19 +183,13 @@ unsigned int HexToDec(byte startp, byte endp)
unsigned int v = 0;
byte pos = startp;
//Serial.println(F("HTD()"));
do
{
if ((pos > 10) || (pos > endp)) break;
//Serial.println(pos);
tv = OneFrame[pos++];
//Serial.println(tv);
tv = tv - '0';
//Serial.println(tv);
if (tv > 9) tv = tv - 7;
//Serial.println(tv);
v = v << 4;
v = v | tv;
......@@ -244,75 +240,59 @@ void LoadFromEEPROM()
val = EEPROM.read(SaveAddr);
SaveAddr++;
//Serial.print(SaveCounter);
//Serial.print(F(" "));
//Serial.println(val);
if (SaveCounter < 10)
{
FadeTimer[SaveCounter] = val;
//Serial.println(F("FT"));
//break;
}
if ((SaveCounter > 9) && (SaveCounter < 20))
{
LEDValuesA[SaveCounter - 10] = val;
//Serial.println(F("LVA"));
}
if ((SaveCounter > 19) && (SaveCounter < 30))
{
LEDCommandsA[SaveCounter - 20] = val;
//Serial.println(F("LCA"));
}
if ((SaveCounter > 29) && (SaveCounter < 40))
{
LEDTimersA[SaveCounter - 30] = val;
//Serial.println(F("LTA"));
}
if ((SaveCounter > 39) && (SaveCounter < 50))
{
LEDTimerValuesA[SaveCounter - 40] = val;
//Serial.println(F("LTVA"));
}
if ((SaveCounter > 49) && (SaveCounter < 60))
{
LEDValuesB[SaveCounter - 50] = val;
//Serial.println(F("LVB"));
}
if ((SaveCounter > 59) && (SaveCounter < 70))
{
LEDCommandsB[SaveCounter - 60] = val;
//Serial.println(F("LCB"));
}
if ((SaveCounter > 69) && (SaveCounter < 80))
{
LEDTimersB[SaveCounter - 70] = val;
//Serial.println(F("LTB"));
}
if ((SaveCounter > 79) && (SaveCounter < 90))
{
LEDTimerValuesB[SaveCounter - 80] = val;
//Serial.println(F("LTVB"));
}
if ((SaveCounter > 89) && (SaveCounter < 100))
{
FixedFadeA[SaveCounter - 90] = val;
//Serial.println(F("FFA"));
}
if ((SaveCounter > 99) && (SaveCounter < 110))
{
FixedFadeB[SaveCounter - 100] = val;
//Serial.println(F("FFB"));
}
}
......@@ -356,83 +336,65 @@ void SaveToEEPROM(byte go = 0)
{
entrytimer(5);
//Serial.print(F("sc:"));
//Serial.println(SaveCounter);
if (SaveCounter < 10)
{
val = FadeTimer[SaveCounter];
//Serial.println(F("FT"));
}
if ((SaveCounter > 9) && (SaveCounter < 20))
{
val = LEDValuesA[SaveCounter - 10];
//Serial.println(F("LVA"));
}
if ((SaveCounter > 19) && (SaveCounter < 30))
{
val = LEDCommandsA[SaveCounter - 20];
//Serial.println(F("LCA"));
}
if ((SaveCounter > 29) && (SaveCounter < 40))
{
val = LEDTimersA[SaveCounter - 30];
//Serial.println(F("LTA"));
}
if ((SaveCounter > 39) && (SaveCounter < 50))
{
val = LEDTimerValuesA[SaveCounter - 40];
//Serial.println(F("LTVA"));
}
if ((SaveCounter > 49) && (SaveCounter < 60))
{
val = LEDValuesB[SaveCounter - 50];
//Serial.println(F("LVB"));
}
if ((SaveCounter > 59) && (SaveCounter < 70))
{
val = LEDCommandsB[SaveCounter - 60];
//Serial.println(F("LCB"));
}
if ((SaveCounter > 69) && (SaveCounter < 80))
{
val = LEDTimersB[SaveCounter - 70];
//Serial.println(F("LTB"));
}
if ((SaveCounter > 79) && (SaveCounter < 90))
{
val = LEDTimerValuesB[SaveCounter - 80];
//Serial.println(F("LTVB"));
}
if ((SaveCounter > 89) && (SaveCounter < 100))
{
val = FixedFadeA[SaveCounter - 90];
//Serial.println(F("FFA"));
}
if ((SaveCounter > 99) && (SaveCounter < 110))
{
val = FixedFadeB[SaveCounter - 100];
//Serial.println(F("FFB"));
}
exittimer(5);
entrytimer(6);
//Serial.print(F("save:"));
//Serial.println(SaveAddr);
//Serial.println(val);
EEPROM.write(SaveAddr, val); // this takes 2812us to run ??? (3400 with variable access???)
exittimer(6);
......@@ -590,12 +552,9 @@ void AnimateOneLED()
{
static byte LastAnimatedLED = 0;
//Serial.println(F("Animate"));
// 1..9
if (++LastAnimatedLED < 10)
{
//Serial.println(LastAnimatedLED);
AnimateLED(LastAnimatedLED);
}
else
......@@ -608,8 +567,6 @@ void AnimateLED()
{
static unsigned int AnimateLEDTimer = AnimateLEDTimerValue;
//Serial.println(AnimateLEDTimer);
AnimateLEDTimer--;
if (AnimateLEDTimer < 10)
......@@ -657,16 +614,10 @@ void ProcessFrame()
byte LED, CMD, VAL;
byte i, v;
//Serial.println(F("PF()"));
LED = HexToDec(6, 6);
CMD = HexToDec(7, 7);
VAL = HexToDec(8, 9);
//Serial.println(LED);
//Serial.println(CMD);
//Serial.println(VAL);
switch (CMD)
{
// Select A array
......@@ -681,6 +632,34 @@ void ProcessFrame()
ArrayASelected = 0;
break;
}
// copy arrays
case 0xC:
{
//BUG: what do we do with FadeTimer[i]? leave alone?
if (VAL == 0)
{
for (i = 0; i < 10; i++)
{
LEDValuesA[i] = LEDValuesB[i];
LEDCommandsA[i] = LEDCommandsB[i];
LEDTimersA[i] = LEDTimersB[i];
LEDTimerValuesA[i] = LEDTimerValuesB[i];
FixedFadeA[i] = FixedFadeB[i];
}
}
else
{
for (i = 0; i < 10; i++)
{
LEDValuesB[i] = LEDValuesA[i];
LEDCommandsB[i] = LEDCommandsA[i];
LEDTimersB[i] = LEDTimersA[i];
LEDTimerValuesB[i] = LEDTimerValuesA[i];
FixedFadeB[i] = FixedFadeA[i];
}
}
break;
}
// Set delay
case 0xD:
{
......@@ -820,25 +799,18 @@ void ProcessFrame()
break;
}
}
//dumpLEDValues();
}
//// +PRG0800FFC // WRITE 0xFF to addr 0x800
//// +PRG0FFF00D // SAVE ARRAY VALUES TO EEPROM, RELOAD THEM ON STARTUP
void ProcessPRGMsg()
{
//Serial.println(F("ProcessPRGMsg()"));
int ADDR;
byte VAL;
ADDR = HexToDec(5, 7);
VAL = HexToDec(8, 9);
//Serial.println(ADDR);
//Serial.println(VAL);
if ((ADDR == 4095) && (VAL == 0))
{
SaveToEEPROM(1);
......@@ -922,7 +894,6 @@ void CmdStateMachine(char Rx)
CmdZeroAddress = 0;
CmdFFAddress = 0;
CmdCRC = 0;
//CmdCRC = 157; //BUG: OLD CRC algo
CmdStateMachineState = CMDSMREADADDR;
}
......@@ -936,10 +907,6 @@ void CmdStateMachine(char Rx)
CmdCRC = CmdCRC ^ (CmdCRC >> 4);
CmdCRC &= 15;
//BUG: OLD CRC algo
//CmdCRC = ((CmdCRC + CmdCRCW) ^ Rx);
//if (CmdCRCW == 3) CmdCRCW = 12; else CmdCRCW = 3;
if (Rx == '0')
{
CmdZeroAddress++;
......@@ -960,15 +927,6 @@ void CmdStateMachine(char Rx)
if (CmdStateMachineBytesRead == 6)
{
/*
//BUG: remove
do
{
DecrementAddress();
Serial.println(OneFrame);
} while (1);
*/
CmdStateMachineState = CMDSMREADREST;
}
break;
......@@ -986,20 +944,12 @@ void CmdStateMachine(char Rx)
if (CmdStateMachineBytesRead == 11)
{
//BUG: remove
//Serial.println(CmdStateMachineBytesRead);
//Serial.println(CmdCRC);
bool isMulticast = false;
//BUG: remove this last
//Serial.print(F("C:"));
//BUG; comment this out when done debugging commands
//Serial.print(F("c:"));
//Serial.println(CmdCRC);
//BUG: remove when done...
//debugTxFrame();
//dumpOneFrame();
bool isMulticast = false;
if (CmdCRC == HexToDec(10, 10))
{
if (OneFrame[1] == 'P')
......@@ -1032,7 +982,6 @@ void CmdStateMachine(char Rx)
if ((CmdZeroAddress < 5) && (!isMulticast))
{
//Serial.println(F("Decrement And Rebroadcast"));
DecrementAddress();
SetChecksum();
Serial.println(OneFrame);
......@@ -1040,7 +989,6 @@ void CmdStateMachine(char Rx)
if (isMulticast)
{
//Serial.println(F("Rebroadcast Multicast Msg"));
Serial.println(OneFrame);
}
}
......@@ -1054,9 +1002,8 @@ void CmdStateMachine(char Rx)
}
void setup() {
//Serial.begin(9600);
Serial.begin(115200);
Serial.println(F("03022019"));
Serial.println(F("03112019"));
SetTxInput();
pinMode(1, INPUT);
......@@ -1074,39 +1021,19 @@ void setup() {
LoadFromEEPROM();
dumpAllArrays();
//ChecksumTests();
//testGetDigits();
//testIncDec();
//testEEPROMTimes();
//MakeTxFrame(0xFFFFF, 0xA, 0xE, 255);
//PrintTxFrame();
//TestTxCommands();
}
void loop() {
unsigned long t1, t2;
UpdateFade();
UpdateOneLED();
AnimateLED(); // call it every loop, exits with no action if timer has not reached correct value
//t1 = micros();
int serialin = Serial.read();
if (serialin != -1)
{
CmdStateMachine(serialin);
//StrBuff[1] = serialin;
//dumpOneFrame();
//t2 = micros();
//Serial.print("s:");
//Serial.println(t2 - t1);
}
if (printtimers)
......
Markdown is supported
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