LED brightness - not yet tested
This commit is contained in:
parent
aa0961a9a4
commit
2c1f274bc0
|
@ -18,6 +18,7 @@
|
|||
// version MEGA01_2 Added end number information. Needs Archeryclock2401 or newer. (older archeryclock versions don't sent the end number information to arduine)
|
||||
// version MEGA02_1 Changes because of a change in protocoll for AC 241 (nr of archers and E and F shooters) and added functionality: emergency stop, add archers E and F. Changes for signal robustness. (0 (0000) is sent as 12 (1100) to prevent decoding issues when 3 times 0 is sent (000000000000)
|
||||
|
||||
#include <TimerOne.h>
|
||||
#include "utils.h"
|
||||
|
||||
// Commands data structures
|
||||
|
@ -38,6 +39,7 @@ struct cfg_t
|
|||
uint8_t abcd : 3; // unclear meaning
|
||||
uint8_t competition : 3; // unclear meaning
|
||||
uint8_t GroupsNumber : 6;
|
||||
uint8_t threshold;
|
||||
uint8_t : 0;
|
||||
} cfg;
|
||||
|
||||
|
@ -79,6 +81,23 @@ union ReceivedCommand_t {
|
|||
digitsvalue_t d;
|
||||
} ReceivedCommand;
|
||||
|
||||
struct PortStatus_t
|
||||
{
|
||||
uint8_t abcd;
|
||||
uint8_t leftdigit;
|
||||
uint8_t middigit;
|
||||
uint8_t rightdigit;
|
||||
uint8_t traflight;
|
||||
struct
|
||||
{
|
||||
uint8_t red : 1;
|
||||
uint8_t orange : 1;
|
||||
uint8_t green : 1;
|
||||
uint8_t : 0;
|
||||
} power_pin;
|
||||
uint8_t : 0;
|
||||
} PortStatus;
|
||||
|
||||
#define DOTS_bm _BV(7)
|
||||
|
||||
#define ABCD_PORT A
|
||||
|
@ -126,6 +145,40 @@ boolean dataAvailable(char &digit)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void dimmer()
|
||||
{
|
||||
static byte counter = 0;
|
||||
|
||||
// Turn on lights
|
||||
if (counter == 0)
|
||||
{
|
||||
CATPORT(ABCD_PORT) = PortStatus.abcd;
|
||||
CATPORT(LEFTDIGIT_PORT) = PortStatus.leftdigit;
|
||||
CATPORT(MIDDIGIT_PORT) = PortStatus.middigit;
|
||||
CATPORT(RIGHTDIGIT_PORT) = PortStatus.rightdigit;
|
||||
CATPORT(TRAFLIGHT_PORT) = PortStatus.traflight;
|
||||
|
||||
digitalWrite(GREENP_PIN, PortStatus.power_pin.green); // green right side
|
||||
digitalWrite(ORANGEP_PIN, PortStatus.power_pin.orange); // orange right side
|
||||
digitalWrite(REDP_PIN, PortStatus.power_pin.red); // red right side
|
||||
}
|
||||
// Turn off
|
||||
else if (counter == cfg.threshold)
|
||||
{
|
||||
CATPORT(ABCD_PORT) = 0x00;
|
||||
CATPORT(LEFTDIGIT_PORT) = 0x00;
|
||||
CATPORT(MIDDIGIT_PORT) = 0x00;
|
||||
CATPORT(RIGHTDIGIT_PORT) = 0x00;
|
||||
CATPORT(TRAFLIGHT_PORT) = 0x00;
|
||||
|
||||
digitalWrite(REDP_PIN, LOW);
|
||||
digitalWrite(ORANGEP_PIN, LOW);
|
||||
digitalWrite(GREENP_PIN, LOW);
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LR_PIN, INPUT_PULLUP);
|
||||
|
@ -146,6 +199,7 @@ void setup()
|
|||
// Load system configuration
|
||||
cfg.BuzzerStatus = digitalRead(MUTE_PIN) ? BUZZER_ON : BUZZER_OFF;
|
||||
cfg.PanelSide = digitalRead(LR_PIN) ? LEFT : RIGHT;
|
||||
cfg.threshold = digitalRead(BRIGHT_PIN) ? 255 : 128;
|
||||
|
||||
// Communication w/PC for debug or other puroposes
|
||||
Serial.begin(9600);
|
||||
|
@ -154,6 +208,11 @@ void setup()
|
|||
|
||||
// Communication w/XBEE
|
||||
Serial1.begin(9600);
|
||||
|
||||
// Attach TimerOne for light dimming
|
||||
// dimmer() is called every 300ms
|
||||
Timer1.initialize(300);
|
||||
Timer1.attachInterrupt(dimmer);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -183,15 +242,15 @@ void loop()
|
|||
// Parse command only if is same side as this panel (or comamnd says to override)
|
||||
if (ReceivedCommand.d.sideOverride || (ReceivedCommand.d.side == cfg.PanelSide))
|
||||
{
|
||||
CATPORT(MIDDIGIT_PORT) = segment[ReceivedCommand.d.mDigit];
|
||||
CATPORT(RIGHTDIGIT_PORT) = segment[ReceivedCommand.d.rDigit];
|
||||
PortStatus.middigit = segment[ReceivedCommand.d.mDigit];
|
||||
PortStatus.rightdigit = segment[ReceivedCommand.d.rDigit];
|
||||
// Turn on dot between minutes and seconds only if count is in minutes and its digit is a representable value (not dash)
|
||||
if (ReceivedCommand.d.lDigit != CHAR_DASH && ReceivedCommand.d.minutes)
|
||||
{
|
||||
CATPORT(LEFTDIGIT_PORT) = segment[ReceivedCommand.d.lDigit] | DOTS_bm;
|
||||
PortStatus.leftdigit = segment[ReceivedCommand.d.lDigit] | DOTS_bm;
|
||||
}
|
||||
else
|
||||
CATPORT(LEFTDIGIT_PORT) = segment[ReceivedCommand.d.lDigit];
|
||||
PortStatus.leftdigit = segment[ReceivedCommand.d.lDigit];
|
||||
}
|
||||
}
|
||||
// Parsing of TRAFFIC command
|
||||
|
@ -206,30 +265,31 @@ void loop()
|
|||
// Set Traffic lights depending on side switch
|
||||
if (cfg.PanelSide == RIGHT)
|
||||
{
|
||||
digitalWrite(GREENP_PIN, ReceivedCommand.t.TrafficLightRight & _BV(0)); // green right side
|
||||
digitalWrite(ORANGEP_PIN, ReceivedCommand.t.TrafficLightRight & _BV(1)); // orange right side
|
||||
digitalWrite(REDP_PIN, ReceivedCommand.t.TrafficLightRight & _BV(2)); // red right side
|
||||
PortStatus.traflight = (ReceivedCommand.t.TrafficLightRight & _BV(0) ? 0b1001 << 2 : 0) |
|
||||
(ReceivedCommand.t.TrafficLightRight & _BV(1) ? 0b1001 << 1 : 0) |
|
||||
(ReceivedCommand.t.TrafficLightRight & _BV(2) ? 0b1001 : 0);
|
||||
|
||||
CATPORT(TRAFLIGHT_PORT) = (ReceivedCommand.t.TrafficLightRight & _BV(0) ? 0b1001 << 2: 0) |
|
||||
(ReceivedCommand.t.TrafficLightRight & _BV(1) ? 0b1001 << 1 : 0) |
|
||||
(ReceivedCommand.t.TrafficLightRight & _BV(2) ? 0b1001 : 0);
|
||||
PortStatus.power_pin.green = ReceivedCommand.t.TrafficLightRight & _BV(0); // green right side
|
||||
PortStatus.power_pin.orange = ReceivedCommand.t.TrafficLightRight & _BV(1); // orange right side
|
||||
PortStatus.power_pin.red = ReceivedCommand.t.TrafficLightRight & _BV(2); // red right side
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(GREENP_PIN, ReceivedCommand.t.TrafficLightLeft & _BV(0)); // green left side
|
||||
digitalWrite(ORANGEP_PIN, ReceivedCommand.t.TrafficLightLeft & _BV(1)); // orange left side
|
||||
digitalWrite(REDP_PIN, ReceivedCommand.t.TrafficLightLeft & _BV(2)); // red left side
|
||||
PortStatus.traflight = (ReceivedCommand.t.TrafficLightLeft & _BV(0) ? 0b1001 << 2 : 0) |
|
||||
(ReceivedCommand.t.TrafficLightLeft & _BV(1) ? 0b1001 << 1 : 0) |
|
||||
(ReceivedCommand.t.TrafficLightLeft & _BV(2) ? 0b1001 : 0);
|
||||
|
||||
CATPORT(TRAFLIGHT_PORT) = (ReceivedCommand.t.TrafficLightLeft & _BV(0) ? 0b1001 << 2 : 0) |
|
||||
(ReceivedCommand.t.TrafficLightLeft & _BV(1) ? 0b1001 << 1 : 0) |
|
||||
(ReceivedCommand.t.TrafficLightLeft & _BV(2) ? 0b1001 : 0);
|
||||
PortStatus.power_pin.green = ReceivedCommand.t.TrafficLightLeft & _BV(0); // green right side
|
||||
PortStatus.power_pin.orange = ReceivedCommand.t.TrafficLightLeft & _BV(1); // orange right side
|
||||
PortStatus.power_pin.red = ReceivedCommand.t.TrafficLightLeft & _BV(2); // red right side
|
||||
}
|
||||
|
||||
// Set ABCD(EF)
|
||||
digitalWrite(A_PIN, ReceivedCommand.t.ArcherGroups & _BV(0)); //A
|
||||
digitalWrite(B_PIN, ReceivedCommand.t.ArcherGroups & _BV(1)); //B
|
||||
digitalWrite(C_PIN, ReceivedCommand.t.ArcherGroups & _BV(2)); //C
|
||||
digitalWrite(D_PIN, ReceivedCommand.t.ArcherGroups & _BV(3)); //D
|
||||
// Set ABCD(EF) -- x x x x D C B A
|
||||
PortStatus.abcd = ReceivedCommand.t.ArcherGroups & 0x0F;
|
||||
// digitalWrite(A_PIN, ReceivedCommand.t.ArcherGroups & _BV(0)); //A
|
||||
// digitalWrite(B_PIN, ReceivedCommand.t.ArcherGroups & _BV(1)); //B
|
||||
// digitalWrite(C_PIN, ReceivedCommand.t.ArcherGroups & _BV(2)); //C
|
||||
// digitalWrite(D_PIN, ReceivedCommand.t.ArcherGroups & _BV(3)); //D
|
||||
// EF not implemented in this hardware
|
||||
/*
|
||||
digitalWrite(6, (((statevalue >> 7) & B00000111) != 2) and (trafficvalue & 0x4000)); //E
|
||||
|
@ -241,23 +301,22 @@ void loop()
|
|||
// Set not{A,B,C,D,(E,F)}
|
||||
if (cfg.abcd != 6)
|
||||
{
|
||||
uint8_t notABCD_on = 0;
|
||||
// not A is on if archer group A is not selected
|
||||
digitalWrite(notA_PIN, cfg.GroupsNumber > 1 && !(ReceivedCommand.t.ArcherGroups & _BV(0)));
|
||||
PortStatus.abcd |= (cfg.GroupsNumber > 1 && !(ReceivedCommand.t.ArcherGroups & _BV(0))) << 4;
|
||||
|
||||
// not B ~ not D are on if groups are effectively present and are not selected
|
||||
if (cfg.competition != 2 && cfg.competition != 4)
|
||||
{
|
||||
digitalWrite(notB_PIN, cfg.GroupsNumber > 1 && !(ReceivedCommand.t.ArcherGroups & _BV(1)));
|
||||
digitalWrite(notC_PIN, cfg.GroupsNumber > 2 && !(ReceivedCommand.t.ArcherGroups & _BV(2)));
|
||||
digitalWrite(notD_PIN, cfg.GroupsNumber > 3 && !(ReceivedCommand.t.ArcherGroups & _BV(3)));
|
||||
PortStatus.abcd |= (cfg.GroupsNumber > 1 && !(ReceivedCommand.t.ArcherGroups & _BV(1))) << 5;
|
||||
PortStatus.abcd |= (cfg.GroupsNumber > 2 && !(ReceivedCommand.t.ArcherGroups & _BV(2))) << 6;
|
||||
PortStatus.abcd |= (cfg.GroupsNumber > 3 && !(ReceivedCommand.t.ArcherGroups & _BV(3))) << 7;
|
||||
}
|
||||
else
|
||||
/*
|
||||
else // it's free
|
||||
{
|
||||
digitalWrite(notB_PIN, LOW);
|
||||
digitalWrite(notC_PIN, LOW);
|
||||
digitalWrite(notD_PIN, LOW);
|
||||
PortStatus.abcd &= ~0b11100000;
|
||||
}
|
||||
*/
|
||||
|
||||
// EF not implemented in this hardware
|
||||
/*
|
||||
|
@ -265,19 +324,16 @@ void loop()
|
|||
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
|
||||
*/
|
||||
}
|
||||
else
|
||||
/*
|
||||
else // it's free
|
||||
{
|
||||
digitalWrite(notA_PIN, HIGH);
|
||||
digitalWrite(notB_PIN, HIGH);
|
||||
digitalWrite(notC_PIN, HIGH);
|
||||
digitalWrite(notD_PIN, HIGH);
|
||||
PortStatus.abcd &= ~0xF0;
|
||||
|
||||
// EF not implemented in this hardware
|
||||
/*
|
||||
digitalWrite(8, (blinkl));
|
||||
digitalWrite(9, (blinkl));
|
||||
*/
|
||||
//digitalWrite(8, (blinkl));
|
||||
//digitalWrite(9, (blinkl));
|
||||
}
|
||||
*/
|
||||
}
|
||||
// Parsing of STATE command
|
||||
else if (ReceivedCommand.s.cmd == 0b1111)
|
||||
|
|
Loading…
Reference in New Issue