diff --git a/arduino/src/sketch.ino b/arduino/src/sketch.ino index bc4c4d3..2350d08 100644 --- a/arduino/src/sketch.ino +++ b/arduino/src/sketch.ino @@ -1,9 +1,10 @@ #include +RCSwitch mySwitch = RCSwitch(); + +int mode = 0; int incomingByte = 0; boolean on = false; -RCSwitch mySwitch = RCSwitch(); -int mode = 0; void setup() { @@ -15,10 +16,11 @@ void loop() { if(Serial.available()) { incomingByte = Serial.read(); - - switch(mode) - { + + switch (var) { + case 126: + if(on) { controlRCOutlets("0FFF0FFF0000"); Serial.println("Light is off."); @@ -28,12 +30,13 @@ void loop() Serial.println("Light is on."); on = true; } + + break; } - } } void controlRCOutlets(const char* sCodeWord) { mySwitch.sendTriState(sCodeWord); delay(1000); -} +} \ No newline at end of file diff --git a/nodejs/public/javascripts/angularApp.js b/nodejs/public/javascripts/angularApp.js index eb905ff..0b37b28 100644 --- a/nodejs/public/javascripts/angularApp.js +++ b/nodejs/public/javascripts/angularApp.js @@ -25,10 +25,10 @@ app.factory('arduino', ['$http', function($http, auth){ }]); app.controller('MainCtrl', ['$scope', 'arduino', function ($scope, arduino){ - $scope.test = 'Hello World!'; $scope.toggleLight = function(){ - + + arduino.toggleLight(); }; diff --git a/nodejs/routes/index.js b/nodejs/routes/index.js index 7daa819..fc06abe 100644 --- a/nodejs/routes/index.js +++ b/nodejs/routes/index.js @@ -10,10 +10,9 @@ router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); }); -app.get('/toggleLight', function (req, res) { +router.get('/toggleLight', function (req, res) { + serialPort.write(new Buffer('~','ascii')); res.send('switch light'); - serialport.write(new Buffer(0x7E)); }); - module.exports = router;