Code syntax

Is it possible to use such syntax:
function pin2change()
{
signal = hardware.pin2.read() == 0;
}
hardware.pin2.configure(DIGITAL_IN_PULLUP, pin2change);

or

value = First < all ? -1 : 1;

imp is working unstable.

All that syntax looks fine to me. What sort of “unstable”? Using syntax that doesn’t exist would cause Squirrel compile-time or run-time errors that you’d see in your browser, and not really “instability”.

Peter

@peter I’m not so sure about compiler - practical work show that ALL compilers can accept wrong syntax.
In my case syntax:
function pin2change()
{
a=hardware.pin2.read();
if(a==9){
signal = 0;
}
}
hardware.pin2.configure(DIGITAL_IN_PULLUP, pin2change);
works fine, but mentioned above not always detect “0”.
Thats why I’m asking

Sure you’re not getting switch bounce? You may get many pin2change events in quick succession from (eg) a switch attached to pin2.

@Hugo It is electronic switch. Probably switch output level LOW is about imp input level LOW. On border can be instability, if the syntax is ok.

Without knowing the slew rate, it’s still possible you could get multiple events.

What’s the actual code you’re using? (I’m pretty sure you’re not using the if (a==9) code as obviously that wouldn’t work :slight_smile: )

Yes, writing mistake :slight_smile: Of course there must be zero instead 9. I don’t copy-paste piece of code so it can happen…:slight_smile:
Agree about slew rate - imp is very fast controller and can detect multiple events.
So finally I just change to “bouncing contact” standard code and now everything is OK.