January 2015
Beginner
324 pages
7h 42m
English
With the SerialDevice class from Writing a SerialDevice Class, it’s easy to create a GameController class that provides even more convenient access to our motion-sensing Arduino. Here’s its constructor function:
| BrowserGame/GameController/js/game_controller.js | |
| | var GameController = function(path, threshold) { |
| | this.arduino = new SerialDevice(path); |
| | this.threshold = threshold || 325; |
| | this.moveLeft = false; |
| | this.moveRight = false; |
| | this.buttonPressed = false; |
| | this.boundOnReadLine = this.onReadLine.bind(this); |
| | this.arduino.onReadLine.addListener(this.boundOnReadLine); |
| | this.arduino.connect(); |
| | } |
This function defines several properties. First, it creates a property named arduino and initializes ...
Read now
Unlock full access