davejavu1969x
Posts: 2
Joined: Wed Jan 07, 2015 10:38 pm

Web based bot control via keydown/keyup using node / js

Wed Jan 07, 2015 11:37 pm

Hi all,

Am currently trying to get my head around Node and JS. I am currently using Google Coder....

http://googlecreativelab.github.io/code ... ky_lights/

Have completed the 'Blinky Lights' demo project and works perfectly. Then swapped out breadboard for 4-relay board and hooked this up. Also works perfectly, the on-screen button displayed in the 'Blinky Lights' app switches the 1 connected relay on & off as expected.

Also then added following code to the so I can turn the relay on / off by holding down / releasing the up arrow key..

Code: Select all

$(document).bind('keydown',function(e){
    if(e.keyCode == 38) {
        $(this).addClass('press');
        ledOff();
    }
});

$(document).bind('keyup',function(e){
    if(e.keyCode == 38) {
        $(this).addClass('press');
        ledOn();
    }
});
This also works as intended.

I now want to add further key press controls to control other relays and have tried to duplicate within the code anything that obviously refers to LED1 as this is what is being controlled. I have very carefully copied all classes / functions etc and created everything I believe that 'LED2' would logically require but unfortunately it doesn't work and does not seem to be a simple syntax error.

I was going to paste the code then realised that to show original and my hashed version would be nearly 1000 lines of code (my additions to the original are only about 20-30 lines!

Essentially I am trying to build a control interface that will have 3 'turn on relay x whilst key n is pressed' controls and I have zero experience with either node or js - I was rather hoping it would be relatively straightforward but am now completely stumped.

If anyone is able / happy to help I can send the code - or if anyone can point me in the right direction that would be very much appreciated.

davejavu1969x
Posts: 2
Joined: Wed Jan 07, 2015 10:38 pm

Re: Web based bot control via keydown/keyup using node / js

Fri Jan 16, 2015 4:03 pm

Update - I got it working, sort of. Appears my updated code was in fact correct to control multiple GPIOs.

But - there is an apparent bug in the GPIO library being used by Coder, hence having issues.

(I have asked which GPIO library this is but not heard anything yet.)

I adjusted the timings on creating the GPIOs as outputs and this does set everything up correctly and it works *just* - but is very flakey and not really at all usable sadly.

I started this thinking that cursor key control of a bot via a webpage should be a very straightforward matter - it appears not :cry:

If any one has any info or pointers as to how this can be achieved - very much appreciated!

windy54
Posts: 86
Joined: Sat Dec 29, 2012 3:37 pm

Re: Web based bot control via keydown/keyup using node / js

Sun Apr 19, 2015 8:15 am

Hi ,
Came across your post after searching for Google coder .
In case you are still struggling look at the CoderBot website, or Dexter industries website, they have got lots of examples on controlling robots from a webpage. I have used their examples to control my robot.

I am actually looking into how to create an app I can use on Google coder to close the raspberry pi down so that is saves me having to log into the PI to shut t down when we use Google coder in school.

Steve

Return to “Automation, sensing and robotics”