8 Replies Latest reply on Jan 10, 2017 1:27 PM by andr01dm

    Trying to make a simple button, without success

    andr01dm

      Hello.

       

      I'm trying to create what should be a very simple project:  Reading the state of a momentary button switch.  But it is not working as I think it should.

       

      Here's what I'm setting up on my breadboard:

      button-only.jpg

       

      And here's my NodeJS code in XDK:

       

      /* jslint node:true */

      /* jshint unused:true */

       

      "use strict";

       

      var mraa = require("mraa");

      var upm = require("jsupm_button");

       

      var myButton = new upm.Button(31); // 'GP44' on the Sparkfun GPIO Block

       

      var buttonState;

      var periodicActivity = function() {

          // check what the button is up to

          buttonState = myButton.value();  // '1' if pressed, '0' if not

          console.log(buttonState);

      };

      var intervalID = setInterval(periodicActivity, 250); // start checking the button's state

       

      Instead of logging "0" for an unpressed button and "1" for pressed, what I see is that when I first start the program I do get "0", but after pressing the button it is stuck on "1", regardless of if the button is pressed or not.  The only way to reset it to "0" is to reboot the Edison.  I have confirmed that the voltage being sent to pin GP44 is switching between 0v and ~3.3v when pressed, but this state change is being ignored.

       

      I've tried re-flashing the Edison and starting from scratch, with no change.  I must be missing something, but I don't know what it is.  Any suggestions..?