Removed redundancy to improve readability

This commit is contained in:
giuliof 2018-12-18 11:18:05 +01:00
parent 05c930841b
commit b5741db5b1
1 changed files with 27 additions and 77 deletions

View File

@ -47,64 +47,12 @@ int segment[16] = {0x03f, 0x006, 0x05b, 0x04f, 0x066, 0x06d, 0x07d, 0x007, 0x07f
void setup()
{
DDRC = B00000000; // Pins A0 to A5 are inputs
buttonvalue = 0;
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
pinMode(16, OUTPUT);
pinMode(17, OUTPUT);
pinMode(18, OUTPUT);
pinMode(19, OUTPUT);
pinMode(20, OUTPUT);
pinMode(21, OUTPUT);
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
pinMode(24, OUTPUT);
pinMode(25, OUTPUT);
pinMode(26, OUTPUT);
pinMode(27, OUTPUT);
pinMode(28, OUTPUT);
pinMode(29, OUTPUT);
pinMode(30, OUTPUT);
pinMode(31, OUTPUT);
pinMode(32, OUTPUT);
pinMode(33, OUTPUT);
pinMode(34, OUTPUT);
pinMode(35, OUTPUT);
pinMode(36, OUTPUT);
pinMode(37, OUTPUT);
pinMode(38, OUTPUT);
pinMode(39, OUTPUT);
pinMode(40, OUTPUT);
pinMode(41, OUTPUT);
pinMode(42, OUTPUT);
pinMode(43, OUTPUT);
pinMode(44, OUTPUT);
pinMode(45, OUTPUT);
pinMode(46, OUTPUT);
pinMode(47, OUTPUT);
pinMode(48, OUTPUT);
pinMode(49, OUTPUT);
pinMode(50, OUTPUT);
pinMode(51, OUTPUT);
pinMode(52, OUTPUT);
pinMode(53, OUTPUT);
pinMode(A8, OUTPUT);
pinMode(A9, OUTPUT);
pinMode(A10, OUTPUT);
pinMode(A11, OUTPUT);
pinMode(A12, OUTPUT);
pinMode(A13, OUTPUT);
pinMode(A14, OUTPUT);
pinMode(A15, OUTPUT);
// All following port banks are outputs for transistors array
DDRF = 0xFF; // Analog 0~7
DDRK = 0xFF; // Analog 8~15
DDRL = 0xFF;
DDRA = 0xFF;
DDRC = 0xFF;
remember1 = 0;
loop1 = 0;
@ -127,6 +75,8 @@ void loop()
inputString = ""; // Clear inputString
if (Serial.available())
{
// number string is received. If '\n' terminate parsing.
while ((Serial.available()))
{
char digit = Serial.read(); // Read serial buffer
@ -182,16 +132,16 @@ void loop()
digitalWrite(15, (trafficvalue & 0x1000) ? HIGH : LOW); //C
digitalWrite(14, (trafficvalue & 0x2000) ? HIGH : LOW); //D
digitalWrite(6, ((((statevalue >> 7) & B00000111) == 2) ? LOW : HIGH) and ((trafficvalue & 0x4000) ? HIGH : LOW)); //E
digitalWrite(7, ((((statevalue >> 7) & B00000111) == 2) ? LOW : HIGH) and ((trafficvalue & 0x8000) ? HIGH : LOW)); //F
digitalWrite(A15, ((((statevalue >> 7) & B00000111) != 2) ? LOW : HIGH) and ((trafficvalue & 0x4000) ? HIGH : LOW)); //green right arrow for fita finals
digitalWrite(39, ((((statevalue >> 7) & B00000111) != 2) ? LOW : HIGH) and ((trafficvalue & 0x8000) ? HIGH : LOW)); //green left arrow for fita finals
digitalWrite(6, (((statevalue >> 7) & B00000111) != 2) and (trafficvalue & 0x4000)); //E
digitalWrite(7, (((statevalue >> 7) & B00000111) != 2) and (trafficvalue & 0x8000)); //F
digitalWrite(A15, (((statevalue >> 7) & B00000111) == 2) and (trafficvalue & 0x4000)); //green right arrow for fita finals
digitalWrite(39, (((statevalue >> 7) & B00000111) == 2) and (trafficvalue & 0x8000) ); //green left arrow for fita finals
//(((((statevalue>>7)&B00000111)=2)?LOW:HIGH) and )
if (digitalRead(A4))
{ //buzzer yes/no switch
digitalWrite(18, (trafficvalue & 0x0008) ? HIGH : LOW); //buzzer
digitalWrite(18, trafficvalue & 0x0008); //buzzer
}
else
{
@ -218,22 +168,22 @@ void loop()
if (blinkkk > 1200)
{
blinkr = 0;
blinkl = ((blinkk > 200) ? HIGH : LOW);
blinkl = (blinkk > 200);
}
else
{
blinkr = ((blinkk > 200) ? HIGH : LOW);
blinkr = (blinkk > 200);
blinkl = 0;
};
if ((((statevalue >> 4) & B00000111) != 6) ? HIGH : LOW)
if (((statevalue >> 4) & B00000111) != 6)
{
digitalWrite(2, (((((statevalue >> 13) & B00000111) < 1) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 2) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 4) ? LOW : HIGH) and (not(trafficvalue & 0x0400) ? HIGH : LOW))); //notA. Is on if Archer A exist but it is not his/her turn to shoot
digitalWrite(3, (((((statevalue >> 13) & B00000111) < 1) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 2) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 4) ? LOW : HIGH) and (not(trafficvalue & 0x0800) ? HIGH : LOW))); //notB. Is on if Archer B exist but it is not his/her turn to shoot
digitalWrite(4, (((((statevalue >> 13) & B00000111) < 2) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 2) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 4) ? LOW : HIGH) and (not(trafficvalue & 0x1000) ? HIGH : LOW))); //notC. Is on if Archer C exist but it is not his/her turn to shoot
digitalWrite(5, (((((statevalue >> 13) & B00000111) < 3) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 2) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 4) ? LOW : HIGH) and (not(trafficvalue & 0x2000) ? HIGH : LOW))); //notD. Is on if Archer D exist but it is not his/her turn to shoot
digitalWrite(8, (((((statevalue >> 13) & B00000111) < 4) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 2) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 4) ? LOW : HIGH) and (not(trafficvalue & 0x4000) ? HIGH : LOW))); //notE. Is on if Archer E exist but it is not his/her turn to shoot
digitalWrite(9, (((((statevalue >> 13) & B00000111) < 5) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 2) ? LOW : HIGH) and ((((statevalue >> 7) & B00000111) == 4) ? LOW : HIGH) and (not(trafficvalue & 0x8000) ? HIGH : LOW))); //notF. Is on if Archer F exist but it is not his/her turn to shoot
digitalWrite(2, ((((statevalue >> 13) & B00000111) >= 1) and (((statevalue >> 7) & B00000111) != 2) and (((statevalue >> 7) & B00000111) != 4) and not(trafficvalue & 0x0400))); //notA. Is on if Archer A exist but it is not his/her turn to shoot
digitalWrite(3, ((((statevalue >> 13) & B00000111) >= 1) and (((statevalue >> 7) & B00000111) != 2) and (((statevalue >> 7) & B00000111) != 4) and not(trafficvalue & 0x0800))); //notB. Is on if Archer B exist but it is not his/her turn to shoot
digitalWrite(4, ((((statevalue >> 13) & B00000111) >= 2) and (((statevalue >> 7) & B00000111) != 2) and (((statevalue >> 7) & B00000111) != 4) and not(trafficvalue & 0x1000))); //notC. Is on if Archer C exist but it is not his/her turn to shoot
digitalWrite(5, ((((statevalue >> 13) & B00000111) >= 3) and (((statevalue >> 7) & B00000111) != 2) and (((statevalue >> 7) & B00000111) != 4) and not(trafficvalue & 0x2000))); //notD. Is on if Archer D exist but it is not his/her turn to shoot
digitalWrite(8, ((((statevalue >> 13) & B00000111) >= 4) and (((statevalue >> 7) & B00000111) != 2) and (((statevalue >> 7) & B00000111) != 4) and not(trafficvalue & 0x4000))); //notE. Is on if Archer E exist but it is not his/her turn to shoot
digitalWrite(9, ((((statevalue >> 13) & B00000111) >= 5) and (((statevalue >> 7) & B00000111) != 2) and (((statevalue >> 7) & B00000111) != 4) and not(trafficvalue & 0x8000))); //notF. Is on if Archer F exist but it is not his/her turn to shoot
}
else
{
@ -255,7 +205,7 @@ void loop()
digitalWrite(20, (trafficvalue & 0x0020) ? HIGH : LOW); //orange right side
digitalWrite(21, (trafficvalue & 0x0040) ? HIGH : LOW); //red right side
//digits
digitalWrite(23, ((rightcountvalue & 0x0008) ? HIGH : LOW) and ((segment[leftdigit] == 0x040) ? LOW : HIGH)); //dots to indicate minutes or seconds indication
digitalWrite(23, (rightcountvalue & 0x0008) and (segment[leftdigit] != 0x040)); //dots to indicate minutes or seconds indication
rightdigit = ((rightcountvalue >> 4) & B00001111);
middigit = ((rightcountvalue >> 8) & B00001111);
leftdigit = ((rightcountvalue >> 12) & B00001111);
@ -263,11 +213,11 @@ void loop()
else //left side
{
//Trafic lights:
digitalWrite(19, (trafficvalue & 0x0080) ? HIGH : LOW); //green left side
digitalWrite(20, (trafficvalue & 0x0100) ? HIGH : LOW); //orange left side
digitalWrite(21, (trafficvalue & 0x0200) ? HIGH : LOW); //red left side
digitalWrite(19, trafficvalue & 0x0080); //green left side
digitalWrite(20, trafficvalue & 0x0100); //orange left side
digitalWrite(21, trafficvalue & 0x0200); //red left side
//digits
digitalWrite(23, ((leftcountvalue & 0x0008) ? HIGH : LOW) and ((segment[leftdigit] == 0x040) ? LOW : HIGH)); //dots to indicate minutes or seconds indication
digitalWrite(23, (leftcountvalue & 0x0008) and (segment[leftdigit] != 0x040) ); //dots to indicate minutes or seconds indication
rightdigit = ((leftcountvalue >> 4) & B00001111);
middigit = ((leftcountvalue >> 8) & B00001111);
leftdigit = ((leftcountvalue >> 12) & B00001111);