L298n.Driver (L298N v0.1.0)

View Source

GenServer process for managing L298N motor driver hardware interface.

This module handles the low-level GPIO interactions with the L298N chip, including PWM control for speed and digital pins for direction control.

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets current motor speeds.

Sets the speed for motor A only.

Sets the speed for motor B only.

Sets the speed and direction for both motors.

Starts the L298N driver GenServer.

Stops all motors.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_motor_speeds(server \\ __MODULE__)

Gets current motor speeds.

set_motor_a(percent, server \\ __MODULE__)

Sets the speed for motor A only.

set_motor_b(percent, server \\ __MODULE__)

Sets the speed for motor B only.

set_motors(motor_a_percent, motor_b_percent, server \\ __MODULE__)

Sets the speed and direction for both motors.

Parameters

  • motor_a_percent - Speed for motor A (-100 to 100)
  • motor_b_percent - Speed for motor B (-100 to 100)

start_link(opts)

Starts the L298N driver GenServer.

Parameters

  • opts - Keyword list with motor configurations

Options

  • :motor_a - Map with :in1, :in2, :en pin numbers for motor A
  • :motor_b - Map with :in1, :in2, :en pin numbers for motor B
  • :name - Process name (defaults to __MODULE__)

stop_all(server \\ __MODULE__)

Stops all motors.