Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

For this exercise, we will create a button that gradually turns a lamp on when pressed, then off again when unpressed.

...

  • Create a temporary push button (basic).

  • Use the button to gradually control a lamp object (advanced).

Making a Temporary Push Button

A temporary push button is a button that only emits a signal while pressed. When released, the signal turns off again.

...

Save the project and run the simulator. Pressing and releasing the button should change the Switch/Lamp state:

...

Changing a Value Gradually

Now, create another tag that will gradually change between 0 and 100:

...

Code Block
tag.write("isPressed", true);
var amountPressed = tag.read("amountPressed");
do {
	amountPressed += 1;
	if (amountPressed > 100) amountPressed = 100;
	tag.write("amountPressed", amountPressed);
	thread.msleep(10);
} while (tag.read("isPressed"));

...

Code Block
tag.write("isPressed", false);
var amountPressed = tag.read("amountPressed");
do {
	amountPressed -= 1;
	if (amountPressed < 0) amountPressed = 0;
	tag.write("amountPressed", amountPressed);
	thread.msleep(10);
} while (!tag.read("isPressed") && amountPressed > 0);

...