Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env node
// From: https://developers.google.com/sheets/api/quickstart/nodejs#step_3_set_up_the_sample
const i2c = require('i2c-bus');
const fs = require('fs');
const util = require('util');
const readline = require('readline');
const {google} = require('googleapis');
const sheetID = '1BX6R8GhUqUXCKMP2NbJWRahR7Y2RR_ycLzn1Y3z7f7A';
const ms = 15*1000; // Repeat time
// Read the i2c temp sensors
const bus = 2;
const tmp101 = [0x48, 0x4a];
const sensor = i2c.openSync(bus);
// If modifying these scopes, delete credentials.json.
const SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
const TOKEN_PATH = 'token.json';
// Load client secrets from a local file.
fs.readFile('credentials.json', (err, content) => {
if (err) return console.log('Error loading client secret file:', err);
// Authorize a client with credentials, then call the Google Sheets API.
authorize(JSON.parse(content), recordTemp);
});
/**
* Create an OAuth2 client with the given credentials, and then execute the
* given callback function.
* @param {Object} credentials The authorization client credentials.
var bus = 1;
var matrix = 0x70;
var time = 1000; // Delay between images in ms
// The first byte is GREEN, the second is RED.
var smile = new Buffer([0x00, 0x3c, 0x00, 0x42, 0x28, 0x89, 0x04, 0x85,
0x04, 0x85, 0x28, 0x89, 0x00, 0x42, 0x00, 0x3c
]);
var frown = new Buffer([0x3c, 0x00, 0x42, 0x00, 0x85, 0x20, 0x89, 0x00,
0x89, 0x00, 0x85, 0x20, 0x42, 0x00, 0x3c, 0x00
]);
var neutral =new Buffer( [0x3c, 0x3c, 0x42, 0x42, 0xa9, 0xa9, 0x89, 0x89,
0x89, 0x89, 0xa9, 0xa9, 0x42, 0x42, 0x3c, 0x3c
]);
var display = i2c.openSync(bus);
display.writeByteSync(matrix, 0x21, 0x01); // Start oscillator (p10)
display.writeByteSync(matrix, 0x81, 0x01); // Disp on, blink off (p11)
display.writeByteSync(matrix, 0xe7, 0x01); // Full brightness (page 15)
setTimeout(doFrown, 0);
setTimeout(doNeutral, 1*time);
setTimeout(doSmile, 2*time);
function doFrown() {
display.writeI2cBlockSync(matrix, 0x00, frown.length, frown);
}
function doNeutral() {
display.writeI2cBlockSync(matrix, 0x00, neutral.length, neutral);
}
// options.address is _always_ sent by all I2C component classes in
// Johnny-Five
const address = options.address;
// options.bus is optional
const bus = typeof(options.bus) !== 'undefined' ? options.bus : this._defaultI2cBus;
// associate the address to the bus
if (!this._addressToBus.hasOwnProperty(address)) {
this._addressToBus[address] = bus;
}
// create an i2c-bus object for the I2C bus
if (!this._i2cBuses.hasOwnProperty(bus)) {
this._i2cBuses[bus] = i2cBus.openSync(bus);
}
return this;
};
#!/usr/bin/env node
// Displays a clock on the LED matrix
// Mark A. Yoder
// 17-Sept-2016
// npm install -g i2c-bus
var i2c = require('i2c-bus');
// var util = require('util');
var bus = 1;
var matrix = 0x70;
var display = i2c.openSync(bus);
// position maps index to a location around the outside of the display
// 0,0 is the bottom left. Starts at top middle
position = new Array(28);
var i;
for(i=0; i<4; i++) {
position[i] = [i+4, 7];
}
for(; i<11; i++) { // Head down the right side
position[i] = [7, 11-i];
}
for(; i<18; i++) { // Left across the bottom
position[i] = [18-i, 0];
}
for(; i<25; i++) { // Up the left side
position[i] = [0, i-18];
* Javascript version.
*
* Copyright (c) 2015-2016 Jason Heard
* Licensed under the MIT license.
*/
"use strict";
var i2cBus = require("i2c-bus");
var Pca9685Driver = require("../").Pca9685Driver;
// PCA9685 options
var options = {
i2c: i2cBus.openSync(1),
address: 0x40,
frequency: 50,
debug: true
};
// pulse lengths in microseconds (theoretically, 1.5 ms
// is the middle of a typical servo's range)
var pulseLengths = [1300, 1500, 1700];
var steeringChannel = 0;
// variables used in servoLoop
var pwm;
var nextPulse = 0;
var timer;
function init(brightnessValue) {
var wire = i2c.openSync(1);
wire.writeByteSync(i2c_address, cmd_set_mode, parseInt(mode_5x11, 2));
wire.writeByteSync(i2c_address, cmd_set_brightness, Number(brightnessValue));
return wire;
}
async started() {
this.i2cBus = i2c.openSync(this.settings.i2cDevice);
this.measurementInterval = setInterval(this.updateMeasurementsCache, 100);
this.updateInterval = setInterval(this.updateState, 500);
},
[getDevice](address) {
let device = this[devices][address];
if (device === undefined) {
device = i2c.openSync(getBoardRevision() === VERSION_1_MODEL_B_REV_1 ? 0 : 1);
this[devices][address] = device;
}
return device;
}
var i2c = require('i2c-bus')
var i2c1 = i2c.openSync(1);
var i2c_address = 0x60;
var cmd_set_mode = 0x00;
var cmd_set_brightness = 0x19;
var cmd_set_pixels = 0x01;
var mode_5x11 = "00000011";
var max_brightness = 8;
var brightness = 0;
i2c1.writeByteSync(i2c_address, cmd_set_brightness, brightness);
i2c1.writeByteSync(i2c_address, cmd_set_brightness, parseInt(mode_5x11, 2));
var buffer = 2;
PCF8574A.prototype.open = function() {
this._i2c = i2cBus.openSync(this._bus, {forceAccess: true});
this._i2c.sendByteSync(this._address, 0x00);
};