Skip to content

Add Waveform Chain command #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

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