Examples
var rsw = new RotarySwitch(PORT_2C, PORT_4D);
var value = 0;
while(true) {
var newValue = value + rsw.getDelta();
// Only print value if it changes
if (value != newValue) {
value = newValue;
print("Value = " + value);
}
if (rsw.clicked()) print("Button clicked");
}
API
RotarySwitch(port2, port4);
getDelta(); // get +/- change in rotation since the last vall to getDelta()
on(); // returns true if button is pressed
off(); // returns true if button is not pressed
clicked(); // returns true if button has been pressed and released since the last call
Note that clicked()
returns true
once if at least one button click has been detected since the last call. Subsequent calls to clicked()
will return false
unless another button click is detected.