var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
var b = require('bonescript');

app.listen(1000);
// socket.io options go here
io.set('log level', 2);   // reduce logging - set 1 for warn, 2 for info,3 
for debug
io.set('browser client minification', true);  // send minified client
io.set('browser client etag', true);  // apply etag caching logic basedon 
version number

console.log('Server running on: http://' + getIPAddress() + ':1000');
//pwm pin
var pwmPin1 = "P9_14";
var pwmPin2 = "P8_19";

//motor 1
var ain1Pin = "P9_13";
var ain2Pin = "P9_15";

//motor 2
var ain1Pin2 = "P8_10";
var ain2Pin2 = "P8_12";

// configure pins
b.pinMode(pwmPin1, b.OUTPUT);
b.pinMode(pwmPin2, b.OUTPUT);
b.pinMode(ain1Pin, b.OUTPUT);
b.pinMode(ain2Pin, b.OUTPUT);
b.pinMode(ain1Pin2, b.OUTPUT);
b.pinMode(ain2Pin2, b.OUTPUT);

function handler (req, res) {
  fs.readFile('Project 16.html',    // load html file
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }
    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {
  // listen to sockets and write analog values to PWM pins
   socket.on('pwmPin', function (data) {
      console.log(data);
      if (data.value >50){
          forwards((data/100 - 0.5) * 2);
          console.log("Forwards");
      }
      else {
          backwards ((0.5 - data/100) * 2);
          console.log("backwards");
      }
    });
});

function forwards(duty) {
    var value = duty;
   //Arm motors
    b.analogWrite(pwmPin1, value); 
    b.analogWrite(pwmPin2, value); 
   //Write values 
    b.digitalWrite(ain1Pin, 1);
    b.digitalWrite(ain2Pin, 0);
    b.digitalWrite(ain1Pin2, 1);
    b.digitalWrite(ain2Pin2, 0);
}

function backwards(duty) {
    var value = duty;
    //Arm motors
    b.analogWrite(pwmPin1, value); 
    b.analogWrite(pwmPin2, value);
    //Write values
    b.digitalWrite(ain1Pin, 0);
    b.digitalWrite(ain2Pin, 1);
    b.digitalWrite(ain1Pin2, 0);
    b.digitalWrite(ain2Pin2, 1);
}
// Get server IP address on LAN
function getIPAddress() {
  var interfaces = require('os').networkInterfaces();
  for (var devName in interfaces) {
    var iface = interfaces[devName];
    for (var i = 0; i < iface.length; i++) {
      var alias = iface[i];
      if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' &&
      !alias.internal)
        return alias.address;
    }
  }
  return '0.0.0.0';
}

and here is the HTML software for this project...

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>BBB and Geaux!</title>
    <script src="/socket.io/socket.io.js"></script>
    <script>
    var socket = io.connect();
    // Send data through socket
    function pwmPin(value){
      socket.emit('pwmPin', value);
    }       
    </script>
</head>
<body>
<div data-role="page" id="page1">
    <div data-theme="a" data-role="header">
        <h3>
            BeagleBone Black
        </h3>
    </div>
    <div data-role="content">
        <div data-role="fieldcontain">
            <label for="slider1">
                Geaux!
            </label>
            <input id="slider1" type="range" name="slider" value="50"
             min="0" max="100"
            data-highlight="false" data-theme="b" onChange="pwmPin(value);">
        </div>
    </div>
</div>
</body>
</html>

If there are some software debuggers out there that know how to work around 
my error codes, let a brother know. Thank you.

Seth





On Monday, October 17, 2016 at 10:13:20 PM UTC-5, Mala Dies wrote:
>
> Hello,
>
> I am working out of a book. It is called "30 Beaglebone Black Projects for 
> the Evil Genius." The author has a GitHub.com page online at 
> https://github.com/ChristopherRush/BB-Evil-Genius. I am on Project16.js 
> and Project16.html. I have gotten scores of error codes. I have been 
> unsuccessful updating my Bonescript and Socket.io languages on the BBGW.
>
> If there are any people out there working out of this specific book, 
> please join in. I can sure use some advice and further understanding.
>
> I know it is me that cannot make the software work with my current 
> configuration(s).
>
> Seth
>
> P.S. If you need additional info, please contact me. Thank you and Geaux 
> Cajuns!
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/dd0740b0-37d2-4dfe-a27c-e999e5650cad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to