Game Plan Star Trip: Interfacing with the lights

LDR-1 (Light Driver)



Next up is the LDR as if I lock on one of the lights it won't burn up like a coil. The process of driving the LDR is very similar to driving the SDR so I should be able to take my learnings onto driving the SDR in the future.

The LDR has three 74HC4514 ICs. These ICs have 4 input pins which can configure one of 16 outputs to be active, giving a maximum light count of 48. The Star Trip pinball machine has less than this so some outputs are not connected. The IC also has an enable pin which when set to HIGH will disable all the output pins. The original MCU had the 4 input and 3 enable pins connected via J2. By pushing all three enable pins HIGH the LDR will disable all the lights. The idea of the LDR is you set the 4 pin input to an individual light number, enable the correct 74HC4514 chips enable pin (corresponding to the light you want to light).

If you want to turn on multiple lights at once you actually turn on and off each individual light really fast to give the impression both are lit at the same time. If you are familiar with a LED Matrix it's basically the same thing.

So from an Arduino Uno I connected the following to J1 on the LDR-1 Board.

LDR J1 PinArduino PinsDescription
12LAMP_ENABLE_1
23LAMP_ENABLE_2
54LAMP_ENABLE_3
86LAMP_ADR_1
95LAMP_ADR_2
47LAMP_ADR_3
38LAMP_ADR_4

The Code

Basic example of just turning lights on one by one:
// Pins
const int LAMP_ENABLE_1 = 2;
const int LAMP_ENABLE_2 = 3;
const int LAMP_ENABLE_3 = 4;
const int LAMP_ADR_1 = 6;
const int LAMP_ADR_2 = 5;
const int LAMP_ADR_3 = 7;
const int LAMP_ADR_4 = 8;

// State
const int LAMP_ADR[] = {
 LAMP_ADR_1,
 LAMP_ADR_2,
 LAMP_ADR_3,
 LAMP_ADR_4
};

const int LAMP_ENABLE[] = {
 LAMP_ENABLE_1,
 LAMP_ENABLE_2,
 LAMP_ENABLE_3
};

const int NUMBER_OF_LIGHTS = 48;

// Code
void setup() {
  // Setup the ADR pins
  for(int i=0; i < 4; i++) {
    pinMode(LAMP_ADR[i], OUTPUT);
    digitalWrite(LAMP_ADR[i], LOW);
  }

  // Set all 74HC4514 Chips to disabled
  for(int i=0; i < 3; i++) {
    pinMode(LAMP_ENABLE[i], OUTPUT);
    digitalWrite(LAMP_ENABLE[i], HIGH);
  }
}

void loop() {
  // Walk through lights 0-48 turning on one at a time.
  // As the machine does not have a light in each of the 48 slots
  // there will be gaps in the light show.
  for(int i = 0; i < NUMBER_OF_LIGHTS; i++) {
      turn_on_light(i);
  }
  // You don't want to use delays in the real game. More on this later.
  delay(100);
}

void turn_on_light(int light) {
  // Lights are numbered 0-15 on the first 4514, 
  // 16-31 on the second and 32-47 on the last.
  int lamp = light/16;
  int adr = light % 16;
  // Disable any lights on already (keep only one light on at a time).
  disable_lamps();
  LampADRSet(adr);
  lamp_enable(lamp+1);
}

void LampADRSet(byte light)
{
  for (int i=0;i < 4;i++) {
    if (bitRead(light, i)==1) {
      digitalWrite(LAMP_ADR[i], HIGH);
    } else {
      digitalWrite(LAMP_ADR[i], LOW);
    }
  }
}

void lamp_enable(int chip_number) {
  disable_lamps();
  digitalWrite(LAMP_ENABLE[chip_number-1], LOW);
}

void disable_lamps() {
  for(int i=0; i < 3; i++) {
    digitalWrite(LAMP_ENABLE[i], HIGH);
  }
}

Now we have control of the lights I will move onto the SDR and get the coils making some movement and noise.

Stay Tuned.



Comments

Popular posts from this blog

Pinball Compute Setup

MPF Unittest automation with Bitbucket Pipelines

Bringing a Game Plan Star Trip back from the dead