Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Create a new growHub instance and connect to https://growHub.commongarden.org
var growHub = new GrowInstance({
uuid: 'bfeffe4c-b78c-4f3f-9c5e-827684ea96da',
token: 'xsG6G5PyQMKPycWN5AjZvuSD2K4GmMcn',
component: 'grow-hub',
// Properties can be updated by the API
properties: {
state: null,
duration: 2000,
interval: 5000,
targets: {},
},
light: new five.Light({
controller: 'TSL2561'
}),
multi: new five.Multi({
controller: 'SI7020'
}),
start: function () {
console.log('Grow-Hub initialized.');
// This must be called prior to any I2C reads or writes.
// See Johnny-Five docs: http://johnny-five.io
board.i2cConfig();
board.i2cRead(0x64, 32, function (bytes) {
var bytelist = [];
board.on("ready", function() {
// servo = five.Servo({
//
// pin: 3,
// startAt: 100,
// range: [0, 180],
// interval: 1000
// });
// servo.sweep([0,300]);
// left();
var sensor = false;
for (var i = 0; i <= 0; i++) {
sensor = new five.Light("A" + i);
sensor.on("change", function() {
sensorValues[this.pin] = this.value;
console.log(this.value);
});
}
setInterval(function() {
console.log("----------------");
Object.keys(sensorValues).forEach(function(key) {
console.log(key + ":" + sensorValues[key]);
});
console.log("----------------");
}, 1000);
});
var sensorValues = {};
Object.keys(sensors).forEach(function(key) {
var sensor = new five.Light("A" + key);
if (key == 0) {
// As the gear rolls down the ramp, it covers a light sensor underneath where the
// gear hits the grabber claw. This is what's used by the demo to know whether
// or not it should be dropping a gear or not
sensor.on("change", function() {
//console.log(this.value);
// the Debug below is used to test to be sure the lightThreshold is tuned
// correctly
if (this.value > lightThreshold) {
//if (lightSensorIsBlocked == true) {
//console.log("Changing lightSensorIsBlocked value from false to true");
//}
lightSensorIsBlocked = false;
} else {
//if (lightSensorIsBlocked == false) {
//console.log("Changing lightSensorIsBlocked value from true to false");
board.on('ready', function start() {
// Declare needed variables.
var pH_reading, eC_reading, water_temp, emit_data;
var lux = new five.Light({
controller: 'TSL2561'
});
var multi = new five.Multi({
controller: 'SI7020'
});
var growHub = new Grow({
uuid: '48d7251e-45c2-43b3-84bd-cdac0bd8c412',
token: '3XMJdsSsTqmxMYjEMzaBtqrGwk7hxozv',
component: 'GrowHub',
camera: Cam,
properties: {
light_state: null,
board.on('ready', () => {
const light = new five.Light('a7');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const port = process.env.PORT || 80;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/public/index.html'));