• @PeterD, the initial setup had two issues as pointed out by last two posts:

    1. @AkosLukacs - you can not have watches on pins of different ports - C and A - with same pin numbers - 8, 9, 10: in your case C8, C9, C10, A8, A9, A10. I would not necessarily call them problems, but more so restrictions / constraints https://www.espruino.com/Original#known-­problems . The reason why not same pin numbers of different ports can be used is the way timers can be assigned to be triggered by pin changes. The timers are used to handle the debouncing. - Therefore, to your question in the conversation's title: Yes, there is a limit to how many pins you can watch at one time. With little more hardware - a few chips - you can though extend it almost infinitely.

    2. @maze1980: Input was floating... State changes in a CMOS like hardware need a current to flow - either to 'charge or discharge a gate connected to the pin with or from electrons'... and the charging and discharging has to happen within a reasonable short amount of time in order to make the detection work reliable and predictable, and short means: nanoseconds to milliseconds at most. Setting the pin mode to "input_pull" fixes it... as also indicated in my first response in post #4...

    Latter a lot to take in when 'playing' with micro controllers - software and hardware - especially when new to the field. But there is no reason to be discouraged... it is exciting to enter this world and make it work for you.


    Current to flow is done by connecting something either to ground / GND / 0 Volts (V) or VBB / VDD / 3.3 / 5 V (https://en.wikipedia.org/wiki/IC_power-s­upply_pin), when the' other side is connected to the opposite' - 3.3V or GND, respectively - or simply: the negative and positive pole of a battery. When not connected, no charging or discharging happens.

    The electronic component inside the processor that is connected to a pin is a transistor - a component that can transmit or resist transmission of electrons (hence its name). A transistor has three (3) zones / connections, where one of them controls whether current - electrons - can flow or not - is/are transmitted or not - between the other two. For one of the two types of (Field Effect Transistors / FET) transistors, current flows when the controlling zone is charged, and no current flows when it is discharged. The controlling zone is connected to the micro controller's pin, and the other two zones to the detection circuitry.

    The fun comes when the pin is connected to both sides, but with the twist the one connection is permanent and thru a resistor which 'slows down' the charging and discharging' process, and the other one is only temporary connected - when the switch is pressed.

    Think of the controlling zone of a transistor as of a water bucket where a fat pipe - posing practically no resistances to the water flow - and another very slim pipe - posing a high resistance to water flow - is connected to, and think of the charging and discharging as of filling and emptying of the bucket.

    If the the fat pipe is connected to a (sufficient) water source and the slim pipe to the drain, the bucket will fill, because the draining isn't fast enough to keep the bucket 'empty'. A while after disconnecting the fat pip from the water source, the bucket will eventually be empty.

    Now think of a passage where passing is controlled by the 'fullness' of the bucket: when the bucket is more than two thirds full, things will begin to pass and the surge of passing can be detected and interpreted as the fat pipe has been connected: your switch has been pressed. Otherwise, when bucket is less than a third full, nothing passes / passing stops (decrease of passing can be detected to... and the difference is in the option: trigger / detection "raising" vs. "falling" vs. "both" - and the debounce helps to ignore erroneous "sporadic gulps" or "sporadic throw-ups"... you want to detect only real steady and solid ones...

    As for thinking: with now permanent drain of the bucket, the bucket would eventually be empty after a very long time: all water evaporated... (if conditions right). This explains why the first few button presses worked... but after the gates were charged / discharged, nothing more happened...

    I guess you can make the bridge back to the pinMode(<pin>,"pull_down"); - connecting the pin internally to a current flow resistance to GND - and your switch with practically no resistance - when pressed - connected to the pin and 3.3V, and coding setWatch(<function>,<pin>,options:{edge:­"rising",debounce:50,repeat:true});

    Enjoy the journey in your new world... youtube has tons of good material helping you along this journey... (of course bad and boring - copycats - too... to understand BJTs and FETs -two very different transistor types with two main types of each you can find at: https://www.youtube.com/watch?v=7ukDKVHn­ac4

    and N MOSFET Experiment
    ...and finally https://www.youtube.com/watch?v=p34w6ISo­uZY

    . The third one will confuse you first even more, because when current was discovered and defined, the atomic structure of materia and electrons were not yet... and current is reverse to actual flow of electrons... haha...

    ...and putting the icing on the cake - as it just did for me.. Unintended - this youtube caught my attention... https://www.youtube.com/watch?v=1uEmX5XC­lPY

    ... LOL ... and even more LOOOL watching the youtube companion's clip.


Avatar for allObjects @allObjects started