Skip to content

Latest commit

 

History

History
55 lines (32 loc) · 3.71 KB

API.md

File metadata and controls

55 lines (32 loc) · 3.71 KB

Octofet API

class Octofet

Create an object of type Octofet to communicate with a particular Octofet board. One Octofet board provides 8 power switches also known as "channels".

Octofet(uint8_t pinCS, uint8_t deviceCount = 1)

Constructs a new Octofet board object that uses the default hardware SPI bus.

  • pinCS: the chip select (also known as slave select) pin used to control the shift-register latch. It is marked CS on the Octofet board. Any GPIO pin of the controller may be used.
  • deviceCount: the number of Octofet boards connected in a daisy-chain. If omitted, defines a single Octofet board.

Octofet(uint8_t pinCS, uint8_t pinMOSI, uint8_t pinSCK, uint8_t deviceCount = 1)

Constructs a new Octofet board object that uses a software SPI bus.

  • pinCS: the chip select (also known as slave select) pin used to control the shift-register latch. It is marked CS on the Octofet board. Any GPIO pin of the controller may be used.
  • pinMOSI: the MOSI (Master Out Slave In) pin used to send data to the peripherals. It is marked DI on the Octofet board. Any GPIO pin of the controller may be used.
  • pinSCK: the clock pin used to clock pulses which synchronize data transmission generated by the master. It is marked П on the Octofet board. Any GPIO pin of the controller may be used.
  • deviceCount: the number of Octofet boards connected in a daisy-chain. If omitted, defines a single Octofet board.

Difference between hardware and software SPI is speed. Software SPI runs slower than hardware SPI but hardware SPI works only on specific board pins: MOSI, MISO (not used in Octofet) and SCK.

void begin()

Initializes the given interface, prepares the board for communication. All power switches are set to the turned-off state.

Call this method before interfacing with Octofet. For example, in your setup().

void digitalWrite(uint8_t channel, bool value, uint8_t device = 0)

Sets the state ("on" or "off") of one power switch.

  • channel: the power switch index. Ranges from 0 to 7.
  • value: defines the desired switch state. Valid values: HIGH / 1 / true to turn on or LOW / 0 / false to turn off.
  • device: the index of the affected Octofet in the daisy-chain. Ranges from 0 to n - 1, where n is the number of Octofets in the chain. If omitted, targets Octofet nearest to the controller.

void digitalWrite8(uint8_t value, uint8_t device = 0)

Sets the state ("on" or "off") of all power switches at once.

  • value: 8-bit value for all of 8 power switches. One bit for one channel: 1 is "on" and 0 is "off". For example: 0b10101010.
  • device: the index of the affected Octofet in the daisy-chain. Ranges from 0 to n - 1, where n is the number of Octofets in the chain. If omitted, targets Octofet nearest to the controller.

bool getChannelState(uint8_t channel, uint8_t device = 0)

Returns the last (i.e., current) set state for one power switch of the device. Returns true if turned on or false otherwise.

  • channel: the power switch index. Ranges from 0 to 7.
  • device: the index of the affected Octofet in the daisy-chain. Ranges from 0 to n - 1, where n is the number of Octofets in the chain. If omitted, targets Octofet nearest to the controller.

uint8_t getChannelState8(uint8_t device = 0)

Returns 8-bit value of the last (i.e., current) set state for all 8 power switches of the device at once. One bit for one channel: 1 is "on" and 0 is "off". For example: 0b10101010. The argument device is the index of the affected Octofet in the daisy-chain. Ranges from 0 to n - 1, where n is the number of Octofets in the chain. If omitted, targets Octofet nearest to the controller.