So if you are crazy enough to want to build your own combination uno driving a bally AS-2518-23 lamp driver board and separate Zero crossing detector here is a simple sketch to test your devices are working copy and paste the following into your arduino ide...
/* ======================================================================================================
*ZeroCrossTest.ino
*Feb 2, 2019 Todd Legere
*Purpose: Test arduino communicating with bally AS-2518-23 lamp board and Zero Cross Detector
* Arduino built in LED lamp will flash every 1/2 second to show that Zero Cross detector working
*Open the serial console and choose which lamp pin to turn on.
*By default lamp one on at startup
* ===================================================================================================== */
/* Pin outs from Robodyn Zero cross detector
* ZCD Pin 1 - Uno 5vdc
* ZCD Pin 2 - Common Ground bus
* ZCD Pin 3 - Uno Pin 2
* ZCD Pin 4 - Empty (Not used)
*/
/* Pin outs from Uno to Bally AS 2518-23 board
* Uno Pin 3 - J4 Pin 13 Strobe
* Uno Pin 4 - J4 Pin 14 A0
* Uno Pin 5 - J4 Pin 15 A1
* Uno Pin 6 - J4 Pin 16 A2
* Uno Pin 7 - J4 Pin 17 A3
* Uno Pin 8 - J4 Pin 7 P0
* Uno Pin 9 - J4 Pin 6 P1
* Uno Pin 10 - J4 Pin 5 P2
* Uno Pin 11 - J4 Pin 4 P3
* Uno Pin 5vdc - J4 Pin 3 5vdc
* Uno Pin Grd - Common Ground bus
*/
/* Ground Pins from Bally pins J4
* J4 Pin 1 - Common Ground bus
* J4 Pin 2 - Common Ground bus
* J4 Pin 11 - Common Ground bus
* J4 Pin 12 - Common Ground bus
*/
#define DEBUG 0 // Set to 1 to see Frequency (Value should average to 60Hz)
#define ZERO_DETECT 2 // Your arduino interrupt pin
#define BOARD_LED 13 // on board LED
#define SECONDS 2.0 // Use two samples to avg frequency calc
// volatile required if you are going to reference this variable
// outside of the interrupt procedure
volatile byte zeroCrossCounter = 0;
volatile int count = 0; // Used to calc frequency value
int AOutputs[] = {4,5,6,7}; // Which arduino pin to turn on (1-15)
int UOutputs[] = {8,9,10,11}; // Which arduino pin to decoder (U1 - U4) for its lamp turn on (pins 1-15)
int Strobe_Pin = 3;
char c;
int v;
void setup() {
Serial.begin(115200);
Serial.println("Enter Lamp # to turn on (0-15):");
// You don't need a pullup since you can use the Arduino pullup
pinMode(ZERO_DETECT,INPUT_PULLUP);
pinMode(BOARD_LED,OUTPUT);
digitalWrite(BOARD_LED,LOW);
attachInterrupt(digitalPinToInterrupt(ZERO_DETECT),AcZeroCrossingInterrupt,FALLING);
pinMode (AOutputs[0], OUTPUT);
pinMode (AOutputs[1], OUTPUT);
pinMode (AOutputs[2], OUTPUT);
pinMode (AOutputs[3], OUTPUT);
// Which IC (U1 - U4) chip to speak to
pinMode (UOutputs[0], OUTPUT);
pinMode (UOutputs[1], OUTPUT);
pinMode (UOutputs[2], OUTPUT);
pinMode (UOutputs[3], OUTPUT);
pinMode (Strobe_Pin, OUTPUT);
v = 1; // Turn on lamp 1 in the begining
}
void loop() {
#if DEBUG
delay(SECONDS * 1000);
noInterrupts();
float hz = count / SECONDS/ 2;
interrupts();
Serial.print(hz);
Serial.println("Hz");
#endif
count = 0;
if (Serial.available()) {
c = Serial.read();
if (c != 10) {
v = int(c) - 48;
Serial.println(v);
}
}
/*
* Simple cycle thru lamps 1 - 4 lamp display One at a time
for (int t = 1; t <= 4; t++) {
delay(250);
v = t;
}
*/
}
void AcZeroCrossingInterrupt () {
// Canadian Power is 60Hz, European and other area's 50Hz change counter to match your geo area.
if ( ++zeroCrossCounter == 60 ) { // blink LED approx every 1/2 second
zeroCrossCounter = 0;
digitalWrite(BOARD_LED,!digitalRead(BOARD_LED));
}
count++;
for (byte b = 0; b <=15; b++) {
digitalWrite(UOutputs[0], HIGH);
if (b == v) {
//
for (int a = 0; a<=4; a++) {
if (bitRead(b,a) == 1) {
digitalWrite(AOutputs[a],HIGH);
} else {
digitalWrite(AOutputs[a],LOW);
}
}
digitalWrite(Strobe_Pin,HIGH);
digitalWrite(Strobe_Pin,LOW);
digitalWrite(UOutputs[0], LOW);
}
}
}