Skip to content

PUSH SWITCH SENSOR

Jaume Olivé Petrus edited this page Aug 15, 2017 · 7 revisions

Specification

What Comments
Identifier HALL_SWITCH
Interface GPIO
Provides on 1 = switch active
0 = switch inactive
Properties none

Code

In this example a push switch is attached to GPIO26. Sensor changes are processed using a callback:

s = sensor.attach("PUSH_SWITCH", pio.GPIO26)

s:callback(
   function(magnitude)
      if (magnitude["on"] == 1) then
         print("on")
      else
         print("off")
      end
   end
)

In this example a push switch is attached to GPIO26. Sensor changes are processed using an infinite loop:

s = sensor.attach("PUSH_SWITCH", pio.GPIO26)

while true do
   if (s:read("on") == 1) then
      print("on")
   else
      print("off")
   end
end
Clone this wiki locally