attachInterrupt contents called on startup and stop without event triggered

Hello,
my intention is to have some initial configuration (green light on). When I push the button, yellow, then red light shall be on.

When I start the code below, the function Ampel() will be called once in reverse order although I have not changed the input pin. After that “initialization phase” everything works as intended above. Furthermore, when I push the “stop” button in cloud9, the Ampel() function is called again, this time in correct order (but not expected).

How can I get rid of the “initialization phase” and the “afterrun”?

Help greatly appreciated.
Thank you!
BR Mathias

Code:

var b = require(‘bonescript’);

var red = “P8_13”;
var yellow = “P8_14”;
var green = “P8_15”;

var Button = ‘P8_19’;

var on = b.HIGH;
var off = b.LOW;

b.pinMode(red, b.OUTPUT);
b.pinMode(yellow, b.OUTPUT);
b.pinMode(green, b.OUTPUT);
b.pinMode(Button, b.INPUT);

b.attachInterrupt(Button, true, b.RISING, Ampel);

LED(red, on);
setTimeout(function() {LED(yellow, on);}, 1000);
setTimeout(function() {LED(red, off); LED(yellow, off); LED(green, on);}, 2000);

function Ampel() {

setTimeout(function() {LED(green, off); LED(yellow, on);}, 500);
setTimeout(function() {LED(yellow, off); LED(red, on);}, 1000);
setTimeout(function() {LED(red, off);},2000); // only debug code
}

function LED(xPin, xState){
b.digitalWrite(xPin, xState);}

The callback will happen on startup and detachment, but you can look at the data provided to the callback to figure out if it is actually an interrupt. Otherwise, you’d need to edit the BoneScript code itself.

Thank you for your reply, Jason. Any thoughts on how I can change the code that it will work properly. I’m a newbie to Java and BeagleBone.
Thanks!
Mathias