Class: WallE::Piezo

Inherits:
Object
  • Object
show all
Defined in:
lib/wall_e/components/piezo.rb

Instance Method Summary collapse

Constructor Details

#initialize(pin) ⇒ Piezo

Public: Initialize a Piezo

pin - the Pin the piezo is attached to



7
8
9
10
11
# File 'lib/wall_e/components/piezo.rb', line 7

def initialize(pin)
  @pin = pin
  @pin.set_mode(Pin::PWM)
  @is_on = false
end

Instance Method Details

#offObject

Public: Turn the piezo off.

Returns nothing.



26
27
28
29
# File 'lib/wall_e/components/piezo.rb', line 26

def off
  @is_on = false
  @pin.analog_write(0)
end

#off?Boolean

Pubilc: Indicates if the piezo is currently off.

Returns Boolean.

Returns:

  • (Boolean)


41
42
43
# File 'lib/wall_e/components/piezo.rb', line 41

def off?
  !@is_on
end

#on(tone) ⇒ Object

Public: Turn the piezo on.

tone - the Integer tone to play.

Returns nothing.



18
19
20
21
# File 'lib/wall_e/components/piezo.rb', line 18

def on(tone)
  @is_on = true
  @pin.analog_write(tone)
end

#on?Boolean

Public: Indicates if the piezo is currently on.

Returns Boolean.

Returns:

  • (Boolean)


34
35
36
# File 'lib/wall_e/components/piezo.rb', line 34

def on?
  @is_on
end