You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • Idling is the easy part: It's built in by JavaScript (in the browser) and by @Gordon in the Espruino implementation:

    As opposed to the typical Arduino Loop, Espruino works on events in the hardware layer, which it puts into a queue, and when done with the time critical things in the hardware, it calls the JavaScript interpreter, which picks up the event information in the queue, until all are done, and then goes to (deep) sleep - idle...

    The example below toggles the red LED1 on each button BTN1 press:

    // toggle red LED1 with BTN1
    setBusyIndicator(LED3);
    var isOn = false;
    setWatch(function(){
        isOn = ! isOn;
        digitalWrite(LED1, isOn);
      },{ repeat: true, edge: "rising", debounce:50 });
    

    Q? What does the setBusyIndicator(LED3); do?
    A: It shows you when the processor is busy - literally!

    You will notice that is flickers only very, very briefly, barely noticeable... and that's the time the system is active, otherwise it is in deep sleep - for fast processors it is like bears in winter hibernation...

    If you use the opposite approach - setSleepIndicator(LED2) to show when it is sleeping - your naked eye is still so blinded by the 'night sleep light that it does not notice the very, very, brief off-time while the processor is busy.

    Connecting-Disconnecting may not be what you want in the game, especially if you want a game for reaction between the players. It could provide random eventing / timing, but the time may just be too long...

    With the naked eye is great... because I tried to make a clip of above code upload and run... the red led shows so bright that the camera had just a red glare... and the blue busy indicator LED is not showing. Therefore, I thought first just to write just always 0 to the led, but analogWrite (PWM) comes in handy with 2% duty cycle:

    // toggle red LED1 with BTN1
    setBusyIndicator(LED3);
    var isOn = false;
    setWatch(function(){
        isOn = ! isOn;
        analogWrite(LED1, (isOn) ? 0.02 : 0);
      },BTN1
       ,{ repeat: true
       , edge: "rising"
       , debounce:50 });
    

    There are two clips added: red LED1 bright and dim. Both include an upload and two button presses (down-and-up, 4 click sounds - first switches the LED1 on, third switches it off). In both clips the upload activity is noticeable, but in the dim one only the LED1 off switching post activity of releasing the button is visible, which does not even include any JavaScript part...


    3 Attachments

About

Avatar for allObjects @allObjects started