Skip to content

Conversation

@adrienmo
Copy link
Contributor

@adrienmo adrienmo commented May 2, 2020

You can compose more complex waveform by chaining them.
For example, pulsing a GPIO on and off every 500 ms for 10 times and then 50 ms for 100 times and this forever. Chain can be nested.

pulses_500 = [
  %Pigpiox.Waveform.Pulse{gpio_on: gpio, delay: 500_000},
  %Pigpiox.Waveform.Pulse{gpio_off: gpio, delay: 500_000}
]

Pigpiox.Waveform.add_generic(pulses_500)

{:ok, wave_500} = Pigpiox.Waveform.create()

pulses_50 = [
  %Pigpiox.Waveform.Pulse{gpio_on: gpio, delay: 50_000},
  %Pigpiox.Waveform.Pulse{gpio_off: gpio, delay: 50_000}
]

Pigpiox.Waveform.add_generic(pulses_50)

{:ok, wave_50} = Pigpiox.Waveform.create()

Pigpiox.GPIO.set_mode(gpio, :output)

Pigpiox.Waveform.chain(%Pigpiox.Waveform.ChainElement{
  content: [
    %Pigpiox.Waveform.ChainElement{
      content: [wave_500],
      repeat: 10
    },
    %Pigpiox.Waveform.ChainElement{
      content: [wave_50],
      repeat: 100
    }
  ],
  repeat: :forever
})

Pigpiox.Waveform.repeat(wave_id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant