was Pressed

See if a touch sensor was pressed since the last time it was checked.


If a touch sensor was pressed, then that event is remembered. Once you check if a touch sensor was pressed, that status is set back to false. If you check again before the sensor is touched another time, the was pressed status is false. Only when the sensor is touched will the was pressed status go to true.


  • a boolean value that is true if the sensor was pressed before. It’s false if the sensor was not pressed.


If the touch sensor touch 1 was pressed, show a green status light. Otherwise, set the status light to orange.

forever(function () {
    if (sensors.touch1.wasPressed()) {
    } else {

See also

is pressed, on event