Smartibot - BTN1 and BTN2 access

Posted on
  • I have updated my Smartibot to version 2.04 and last night started to work through some of the examples in the documentation.

    First one I tried was button presses

    setWatch(function(e) {
      if (e.state) print("Button pressed");
      else print("Button released");
    }, BTN, {repeat:true});
    

    When I download this "Button pressed" is printed only when Button A on the smartibot is pressed, nothing when released and nothing for Button B.

    So looking at some examples I added

    var smarti = require("Smartibot");
    

    to the top and this made no difference.

    I then tried the "block" coding and used the set watch construct.
    First block was BTN1 rising and inside I change the colours of the leds. This was then duplicated for BTN1 falling, then I duplicated both for BTN2.

    Downloaded and it worked.
    Tried to change the code but somehow deleted everything, when I started again BTN2 was not available.

    This morning I started to create the post, initially the same problem , no BTN2.
    Tried refreshing the browser still did not work.
    So I downloaded the raw javascript to prove that did not detect BTNB , it did not.

    Then went back to "block" mode and BTN2 is available.

    I am using Chrome on a mac and I am new to java script.

    My questions are:

    1. what is wrong with the raw javascript code I downloaded ?
    2. have I found a bug with the block code ?

    PS should I have tagged this post or posted elsewhere so it is obvious it is a smartibot issue I am having.


    1 Attachment

    • Screenshot 2019-11-19 at 23.10.12.png
  • I don't have a Smartibot, but setting edge:'both' should trigger button press on press and release:

    setWatch(function(e) {
      if (e.state) print("Button pressed");
      else print("Button released");
    }, BTN, {repeat:true; edge:'both'});
    

    Docs with more details

  • }, BTN, {repeat:true; edge:'both'});

    and the button is probably not named BTN. Should be BTN1 or BTN2 according to this

  • I just tried BTN1 and BTN2 , that has sorted that problem. I will see if I can change the documentation here
    http://www.espruino.com/Smartibot

    That just leaves the "block code" issue.

    Thanks for replies, I will have to look at java script so I can better understand the documentation you pointed me at.

  • Glad you got this sorted - I'll change the Smartibot docs now.

    If you need to modify them yourself in the future, the file is here: https://github.com/espruino/EspruinoDocsĀ­/blob/master/boards/Smartibot.md

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Smartibot - BTN1 and BTN2 access

Posted by Avatar for user104966 @user104966

Actions