Skip to content

Commit 494a244

Browse files
committed
Update all DFRobot kit JS examples to support Arduino/Genuino 101
Signed-off-by: deadprogram <[email protected]>
1 parent 20da83a commit 494a244

File tree

11 files changed

+169
-46
lines changed

11 files changed

+169
-46
lines changed

access-control/javascript/dfrobot.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,23 @@
2525

2626
var exports = module.exports = {};
2727

28+
var mraa = require("mraa");
29+
2830
// Initialize the hardware devices
29-
var screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0),
30-
motion = new (require("jsupm_biss0001").BISS0001)(16);
31+
var screen, motion;
3132

3233
exports.init = function(config) {
34+
if (config.platform == "firmata") {
35+
// open connection to firmata
36+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
37+
38+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(520, 521, 516, 517, 518, 519, 512);
39+
motion = new (require("jsupm_biss0001").BISS0001)(528);
40+
} else {
41+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
42+
motion = new (require("jsupm_biss0001").BISS0001)(16);
43+
}
44+
3345
return;
3446
}
3547

air-quality-sensor/javascript/dfrobot.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,22 @@ var exports = module.exports = {};
3030
// pin used to turn on/off the buzzer
3131
var mraa = require("mraa");
3232

33+
var buzzer, air;
34+
3335
// Initialize the DFRobot hardware devices
34-
var buzzer = new mraa.Gpio(15), // aka A1
36+
exports.init = function(config) {
37+
if (config.platform == "firmata") {
38+
// open connection to firmata
39+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
40+
41+
buzzer = new mraa.Gpio(15 + 512); // aka A1
42+
air = new (require("jsupm_gas").MQ2)(2 + 512); // aka A2
43+
} else {
44+
buzzer = new mraa.Gpio(15); // aka A1
3545
air = new (require("jsupm_gas").MQ2)(2); // aka A2
46+
}
3647

37-
buzzer.dir(mraa.DIR_OUT);
38-
39-
exports.init = function(config) {
48+
buzzer.dir(mraa.DIR_OUT);
4049
return;
4150
}
4251

alarm-clock/javascript/dfrobot.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,26 @@ var exports = module.exports = {};
3131
var mraa = require("mraa");
3232

3333
// Initialize the hardware devices
34-
var buzzer = new mraa.Gpio(15), // aka A1
35-
button = new (require("jsupm_grove").GroveButton)(16), // aka A2
36-
rotary = new (require("jsupm_grove").GroveRotary)(3), // A3
37-
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
34+
var buzzer, button, rotary, screen;
3835

3936
buzzer.dir(mraa.DIR_OUT);
4037

4138
exports.init = function(config) {
39+
if (config.platform == "firmata") {
40+
// open connection to firmata
41+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
42+
43+
buzzer = new mraa.Gpio(15 + 512); // aka A1
44+
button = new (require("jsupm_grove").GroveButton)(16 + 512); // aka A2
45+
rotary = new (require("jsupm_grove").GroveRotary)(3 + 512); // A3
46+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(520, 521, 516, 517, 518, 519, 512);
47+
} else {
48+
buzzer = new mraa.Gpio(15); // aka A1
49+
button = new (require("jsupm_grove").GroveButton)(16); // aka A2
50+
rotary = new (require("jsupm_grove").GroveRotary)(3); // A3
51+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
52+
}
53+
4254
return;
4355
}
4456

doorbell/javascript/dfrobot.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,24 @@ var exports = module.exports = {};
3131
var mraa = require("mraa");
3232

3333
// Initialize the DFRobot hardware devices
34-
var buzzer = new mraa.Gpio(15), // aka A1
35-
touch = new (require("jsupm_grove").GroveButton)(16), // aka A2
36-
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
34+
var buzzer, touch, screen;
3735

3836
buzzer.dir(mraa.DIR_OUT);
3937

4038
exports.init = function(config) {
39+
if (config.platform == "firmata") {
40+
// open connection to firmata
41+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
42+
43+
buzzer = new mraa.Gpio(15 + 512); // aka A1
44+
touch = new (require("jsupm_grove").GroveButton)(16 + 512); // aka A2
45+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(520, 521, 516, 517, 518, 519, 512);
46+
} else {
47+
buzzer = new mraa.Gpio(15); // aka A1
48+
touch = new (require("jsupm_grove").GroveButton)(16); // aka A2
49+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
50+
}
51+
4152
return;
4253
}
4354

earthquake-detector/javascript/dfrobot.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,27 @@ var exports = module.exports = {};
3131
var mraa = require("mraa");
3232

3333
// Initialize the DFRobot hardware devices
34-
var screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
35-
var ax = new mraa.Aio(3), // A3
36-
ay = new mraa.Aio(2), // A2
37-
az = new mraa.Aio(1); // A1
34+
var screen, ax, ay, az;
3835

3936
exports.init = function(config) {
37+
if (config.platform == "firmata") {
38+
// open connection to firmata
39+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
40+
41+
ax = new mraa.Aio(3 + 512); // A3
42+
ay = new mraa.Aio(2 + 512); // A2
43+
az = new mraa.Aio(1 + 512); // A1
44+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(520, 521, 516, 517, 518, 519, 512);
45+
} else {
46+
ax = new mraa.Aio(3); // A3
47+
ay = new mraa.Aio(2); // A2
48+
az = new mraa.Aio(1); // A1
49+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
50+
}
51+
4052
return;
4153
}
42-
54+
4355
// Cannot set the background color on this LCD display
4456
exports.color = function(string) {
4557
return;

equipment-activity-monitor/javascript/dfrobot.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,30 @@
2626
var exports = module.exports = {};
2727

2828
// Initialize the DFRobot hardware devices
29+
var mraa = require("mraa");
2930
var mic = require("jsupm_mic");
30-
var sound = new mic.Microphone(1), // A1
31-
vibration = new (require("jsupm_grove").GroveButton)(16), // aka A2
31+
var sound, vibration, screen;
32+
33+
exports.init = function(config) {
34+
if (config.platform == "firmata") {
35+
// open connection to firmata
36+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
37+
38+
sound = new mic.Microphone(1 + 512); // A1
39+
vibration = new (require("jsupm_grove").GroveButton)(16 + 512); // aka A2
40+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(520, 521, 516, 517, 518, 519, 512);
41+
} else {
42+
sound = new mic.Microphone(1); // A1
43+
vibration = new (require("jsupm_grove").GroveButton)(16); // aka A2
3244
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
45+
}
3346

34-
// Initialize the sound sensor
35-
var ctx = new mic.thresholdContext();
36-
ctx.averageReading = 0;
37-
ctx.runningAverage = 0;
38-
ctx.averagedOver = 2;
47+
// Initialize the sound sensor
48+
var ctx = new mic.thresholdContext();
49+
ctx.averageReading = 0;
50+
ctx.runningAverage = 0;
51+
ctx.averagedOver = 2;
3952

40-
exports.init = function(config) {
4153
return;
4254
}
4355

fire-alarm/javascript/dfrobot.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,24 @@ var exports = module.exports = {};
3131
var mraa = require("mraa");
3232

3333
// Initialize the DFRobot hardware devices
34-
var temp = new mraa.Aio(1), // A1
35-
buzzer = new mraa.Gpio(16), // aka A2
34+
var temp, buzzer, screen;
35+
36+
exports.init = function(config) {
37+
if (config.platform == "firmata") {
38+
// open connection to firmata
39+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
40+
41+
temp = new mraa.Aio(1 + 512); // A1
42+
buzzer = new mraa.Gpio(16 + 512); // aka A2
43+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(520, 521, 516, 517, 518, 519, 512);
44+
} else {
45+
temp = new mraa.Aio(1); // A1
46+
buzzer = new mraa.Gpio(16); // aka A2
3647
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
48+
}
3749

38-
buzzer.dir(mraa.DIR_OUT);
50+
buzzer.dir(mraa.DIR_OUT);
3951

40-
exports.init = function(config) {
4152
return;
4253
}
4354

plant-lighting-system/javascript/dfrobot.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,28 @@
2525

2626
var exports = module.exports = {};
2727

28+
var mraa = require("mraa");
29+
2830
// Initialize the DFRobot hardware devices
29-
var light = new (require("jsupm_grove").GroveLight)(1), // A1
30-
moisture = new (require("jsupm_grovemoisture").GroveMoisture)(2), // A2
31-
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
31+
var light, moisture, screen;
3232

3333
exports.init = function(config) {
34+
if (config.platform == "firmata") {
35+
// open connection to firmata
36+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
37+
38+
light = new (require("jsupm_grove").GroveLight)(1 + 512); // A1
39+
moisture = new (require("jsupm_grovemoisture").GroveMoisture)(2 + 512); // A2
40+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(520, 521, 516, 517, 518, 519, 512);
41+
} else {
42+
light = new (require("jsupm_grove").GroveLight)(1); // A1
43+
moisture = new (require("jsupm_grovemoisture").GroveMoisture)(2); // A2
44+
screen = new (require("jsupm_i2clcd").SAINSMARTKS)(8, 9, 4, 5, 6, 7, 0);
45+
}
46+
3447
return;
3548
}
36-
49+
3750
// Displays a message on the LCD
3851
exports.message = function(string, line) {
3952
// pad string to avoid display issues

smart-stove-top/javascript/dfrobot.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,24 @@ var exports = module.exports = {};
3232
var mraa = require("mraa");
3333

3434
// Initialize the DFRobot hardware devices
35-
var temp = new mraa.Aio(1), // A1
36-
buzzer = new mraa.Gpio(16), // aka A2
35+
var temp, buzzer, flame;
36+
37+
exports.init = function(config) {
38+
if (config.platform == "firmata") {
39+
// open connection to firmata
40+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
41+
42+
temp = new mraa.Aio(1 + 512); // A1
43+
buzzer = new mraa.Gpio(16 + 512); // aka A2
44+
flame = new mraa.Aio(3 + 512); // A3
45+
} else {
46+
temp = new mraa.Aio(1); // A1
47+
buzzer = new mraa.Gpio(16); // aka A2
3748
flame = new mraa.Aio(3); // A3
49+
}
3850

39-
buzzer.dir(mraa.DIR_OUT);
51+
buzzer.dir(mraa.DIR_OUT);
4052

41-
exports.init = function(config) {
4253
return;
4354
}
4455

storage-unit-flood-detector/javascript/dfrobot.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ var exports = module.exports = {};
3131
var mraa = require("mraa");
3232

3333
// Initialize the DFRobot hardware devices
34-
var moisture = new (require("jsupm_grovemoisture").GroveMoisture)(1), // A1
34+
var moisture, buzzer;
35+
36+
exports.init = function(config) {
37+
if (config.platform == "firmata") {
38+
// open connection to firmata
39+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
40+
41+
moisture = new (require("jsupm_grovemoisture").GroveMoisture)(1 + 512); // A1
42+
buzzer = new mraa.Gpio(16 + 512); // aka A2
43+
} else {
44+
moisture = new (require("jsupm_grovemoisture").GroveMoisture)(1); // A1
3545
buzzer = new mraa.Gpio(16); // aka A2
46+
}
3647

37-
buzzer.dir(mraa.DIR_OUT);
48+
buzzer.dir(mraa.DIR_OUT);
3849

39-
exports.init = function(config) {
4050
return;
4151
}
4252

watering-system/javascript/dfrobot.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,23 @@ var exports = module.exports = {};
3131
var mraa = require("mraa");
3232

3333
// Initialize the DFRobot hardware devices
34-
var moisture = new (require("jsupm_grovemoisture").GroveMoisture)(1), // A1
34+
var moisture, pump;
35+
36+
exports.init = function(config) {
37+
if (config.platform == "firmata") {
38+
// open connection to firmata
39+
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
40+
41+
moisture = new (require("jsupm_grovemoisture").GroveMoisture)(1 + 512); // A1
42+
pump = new mraa.Gpio(16 + 512); // aka A2
43+
} else {
44+
moisture = new (require("jsupm_grovemoisture").GroveMoisture)(1); // A1
3545
pump = new mraa.Gpio(16); // aka A2
46+
}
3647

37-
// Set GPIO direction to output
38-
pump.dir(mraa.DIR_OUT);
48+
// Set GPIO direction to output
49+
pump.dir(mraa.DIR_OUT);
3950

40-
exports.init = function(config) {
4151
return;
4252
}
4353

@@ -60,7 +70,7 @@ exports.checkFlowOff = function() {
6070

6171
// Turns on the water
6272
exports.turnOn = function() {
63-
var that = this;
73+
var that = this;
6474
pump.write(1);
6575

6676
// check flow started after 10 seconds

0 commit comments

Comments
 (0)