API Reference Constructors and initialization - DhrBaksteen/ArduinoOPL2 GitHub Wiki

Constructor

OPL2::OPL2();
OPL2::OPL2(byte reset, byte address, byte latch);

Before the OPL2 library can be used we first must create an instance of it. There are two constructors available for this; a default constructor which will create a new library instance with default pin numbers and a constructor that allows you to define custom pins to suit your setup.

Arguments
  • byte reset - The Arduino pin connected to the RESET pin of the OPL2 Audio Board
  • byte address - The Arduino pin connected to the A0 pin of the OPL2 Audio Board
  • byte latch - The Arduino pin connected to the LATCH pin of the OPL2 Audio Board

When no arguments are given the default pins will be used. For Arduino these are:

OPL2 pin Arduino pin
RESET 8
A0 9
LATCH 10

The pins for DATA and SHIFT cannot be reassigned.

See also

begin, reset

begin

void OPL2::begin();

The begin function initializes the library and the OPL2 Audio Board by preparing the IO pins of the Arduino and resetting the chip by calling the reset() function. It also calls createShadowRegisters() to set aside a portion of SRAM to contain a copy of the OPL2 registers. This function must be called after creating the library instance, before calling any of the library functions.

For backward compatibility the OPL2::init() function is still available. Internally this function will call begin(). The init() function is deprecated and should no longer be used.

See also

Constructor, reset

reset

void OPL2::reset();

Reset the OPL2 and clear internal registers. This stops all sound and resets the registers to all zeros. This function is called internally when the library is initialized though the begin() function.

See also

Constructor, begin

createShadowRegisters

void OPL2::createShadowRegisters();

This function sets aside a portion of SRAM that will contain a copy of the OPL2 registers. The library uses these registers when reading register values or when changing register values through the getter and setter functions. This function is called from begin(). Normally you wouldn't call this function.

The OPL2 library will only reserve as many bytes as it needs for the shadow registers. Mind that when your program directly calls the write() function it will not update the shadow registers!

See also

begin

⚠️ **GitHub.com Fallback** ⚠️