function printValue1(err, data) { if (err) throw err; if (data>oldData){ console.log('data: '+data +'oldData' +oldData); if(y<7)y=y+1; faq[y][z]=1; for (i=0; i<number; i++){ console.log(faq[i]); var gridToParse = faq[i].join(''); red[i] = parseInt(gridToParse,2); matrix.writeBytes(i*2, [green[i], red[i]]); console.log("empt print to i2c"); } } if (data<oldData){ console.log('data: '+data +'oldData' +oldData); if(y>0)y=y-1; faq[y][z]=1; for (i=0; i<number; i++){ console.log(faq[i]); var gridToParse = faq[i].join(''); red[i] = parseInt(gridToParse,2); matrix.writeBytes(i*2, [green[i], red[i]]); console.log("empt print to i2c"); } } if (oldData !== data) { console.log('position: '+data); //+' speed: '+(oldData-data)); oldData = data; } }
function printValue(err1, data1) { if (err1) throw err1; if (data1>oldData1){ console.log('data1: '+data1 +'oldData1' +oldData1); if(z<7)z=z+1; faq[y][z]=1; for (i=0; i<number; i++){ console.log(faq[i]); var gridToParse = faq[i].join(''); red[i] = parseInt(gridToParse,2); matrix.writeBytes(i*2, [green[i], red[i]]); console.log("empt print to i2c"); } } if (data1<oldData1){ console.log('data1: '+data1 +'oldData1' +oldData1); if(z>0)z=z-1; faq[y][z]=1; for (i=0; i<number; i++){ console.log(faq[i]); var gridToParse = faq[i].join(''); red[i] = parseInt(gridToParse,2); matrix.writeBytes(i*2, [green[i], red[i]]); console.log("empt print to i2c"); } } if (oldData1 !== data1) { console.log('position: '+data1); //+' speed: '+(oldData1-data1)); oldData1 = data1; } }
.seq(function () { wire.writeBytes(BYTE_ENABLE_OUTPUT, [0x01]); wire.writeBytes(BYTE_ENABLE_LEDS, [0xFF, 0xFF, 0xFF]); piglow.clear(); // Clear the piglow wire.writeBytes(BYTE_SET_PWM_VALUES, piglow.getPiglowInstruction()); wire.writeBytes(BYTE_UPDATE, [0xFF]); var i = 0; io.sockets.on('connection', function (socket) { socket.on('update', function (data) { piglow.clear(); piglow.setColor('red', data.red); piglow.setColor('orange', data.orange); piglow.setColor('yellow', data.yellow); piglow.setColor('green', data.green); piglow.setColor('blue', data.blue); piglow.setColor('white', data.white); //console.log(i); // Write new state to piglow wire.writeBytes(BYTE_SET_PWM_VALUES, piglow.getPiglowInstruction()); wire.writeBytes(BYTE_UPDATE, [0xFF]); }); }); })
// Checks which quadrant the cursor and points are in function checkQuadrant(){ if(posy === pointY && wire.address === location){ wire.writeBytes(posy*2, [Math.pow(2,posx)+Math.pow(2,pointX)]); } else{ wire.writeBytes(posy*2, [Math.pow(2,posx)]); } }
//Setup and turn on the 8x8 Bi-Color LED Matrices function setup(){ for(var i=0; i<4; i++){ var wire = new i2c(address[i], {device: '/dev/i2c-1'}); // Points to the i2c address wire.writeBytes(0x21, 0x00); // 8x8 Bi-Color LED Matrix Set-up wire.writeBytes(0x81, 0x00); // Display on and no blinking wire.writeBytes(brightness, 0x00); // Configures the brightness } }
// Function used to clear the old cursor function clearY(){ var buf = wire.readBytes(posy*2,2); var cursor = Math.pow(2,posx); if(buf[0] === cursor){ wire.writeBytes(posy*2, [0]); } else{ wire.writeBytes(posy*2, [buf[0]-cursor]); } }
exports.writeString = function(input){ var data = generateString(input); var buf = new Buffer(4*7); buf.fill(0); for(var i = 0;i < data.length;i++){ buf.writeUInt32LE(data[i],i*4); } wire.writeBytes(0, buf, function(err) {}); wire.writeBytes(34, [1], function(err) {}); //console.log(buf); };
function (status, callback) { if (color === 'red') { matrix.writeBytes(cmd, [status[0] & ~(1 << column), status[1] | (1 << column)], null); } else if (color === 'green') { matrix.writeBytes(cmd, [status[0] | (1 << column), status[1] & ~(1 << column)], null); } else if (color === 'yellow') { matrix.writeBytes(cmd, [status[0] | (1 << column), status[1] | (1 << column)], null); } else { matrix.writeBytes(cmd, [status[0] & ~(1 << column), status[1] & ~(1 << column)], null); } callback(null); }
socket.on('update', function (data) { piglow.clear(); piglow.setColor('red', data.red); piglow.setColor('orange', data.orange); piglow.setColor('yellow', data.yellow); piglow.setColor('green', data.green); piglow.setColor('blue', data.blue); piglow.setColor('white', data.white); //console.log(i); // Write new state to piglow wire.writeBytes(BYTE_SET_PWM_VALUES, piglow.getPiglowInstruction()); wire.writeBytes(BYTE_UPDATE, [0xFF]); });
function app_i2c(server) { var io = require('socket.io')(server); wire.writeBytes(0x16, [0x05], function(err, res){}); wire.writeBytes(0x10, [0,0,0,0,0,0], function(err, res){}); setInterval(function() { wire.readBytes(0x06, 3, function(err, res){ io.sockets.emit('event', { x: signed(res[0]), y: signed(res[1]), z: signed(res[2]), }); }); }, 100); }
function printStatus4(x4) { if(x4.value ==1) { b.digitalWrite(LED4,b.HIGH); if(y<number-1)y=y+1; } if(x4.value ==0) { b.digitalWrite(LED4,b.LOW); console.log("y is " +y); console.log("z is " +z); faq[y][z]=1; for (i=0; i<number; i++) { //console.log(faq[i]); var gridToParse = faq[i].join(''); red[i] = parseInt(gridToParse,2); matrix.writeBytes(i*2, [green[i], red[i]]); } } }
bbbI2C.prototype.SetValue = function (channel,inValue) { //console.log("DAC %d = ", channel,inValue); channel = (channel & 0x07) + 0x30; //console.log("DAC %x = ", channel,inValue); if(inValue > 3.89) inValue = 3.89; if(inValue < 1.11) inValue = 1.11; // console.log(" limited Invalue = ", inValue); var scaleFactor = 4095.0 / 5.0; //console.log("scaleFactor = ", scaleFactor); var scaledValue = inValue * scaleFactor; // console.log("scaledValue = ", scaledValue); var value = ~~(scaledValue); // truncate to int // console.log("truncated scaled value = %d = %s",value, value.toString(16)); //var temp = (((value & 0x0FF0 ) >> 4) >>>0) | (((value & 0x000F) << 12) >>>0); var tempA = value & 0x0FF0; // mask middle byte tempA = tempA >> 4 >>>0; // shift to right justify, zero fill tempA = tempA & 0xFF; // make a byte size var tempB = value & 0x0F; // mask least significat nibble tempB = tempB << 4 >>>0; // shift left one nibble, zero fill tempB = tempB & 0xFF; // make a byte size //console.log("DAC A Set to ", tempB.toString(16), "-",tempA.toString(16)); // dac.writeBytes(CH_A, [0x7F,0xF0], errorHandler); dac.writeBytes(channel, [tempA, tempB], errorHandler); };
function printStatus1(x1) { if(x1.value ==1) { b.digitalWrite(LED1,b.HIGH); if(z>0)z=z-1; } if(x1.value ==0) { b.digitalWrite(LED1,b.LOW); console.log("y is " +y); console.log("z is " +z); faq[y][z]=1; for (i=0; i<number; i++) { console.log(faq[i]); var gridToParse = faq[i].join(''); red[i] = parseInt(gridToParse,2); matrix.writeBytes(i*2, [green[i], red[i]]); console.log("empt print to i2c"); } } }
sensor1.writeBytes(confPointer, [configRegisterValue], function(err) { sensor1.writeBytes(tLpointer, [thresholdL], function(err) { sensor1.writeBytes(tHpointer, [thresholdH], function(err) { setTimeout(main, 1000); }); }); });
function (callback) { // Write select pressure command to control register wire.writeBytes(BMP085_CONTROL_REGISTER, [BMP085_SELECT_PRESSURE + (options.mode << 6)], function(err, data) { setTimeout(function () { callback(err); }, 28); }); },
/*Checks the y coordinates and updates the LED Matrix If the analog value is <0.1 it moves down, if its >0.9 it moves up. */ function checkY() { var yCoord; yCoord = b.analogRead('P9_38'); if(yCoord<0.05){ clearY(); // Delete trailing cursor posy+=1; final = fix(); wire.writeBytes(posy*2, [Math.pow(2,posx)+final]); // Updates cursor } if(yCoord>0.95){ clearY(); // Delete trailing cursor posy-=1; var final = fix(); wire.writeBytes(posy*2, [Math.pow(2,posx)+final]); // Updates cursor } return posy; }
var initialize = function(args) { if (args.lowPass) { options.lowPass = args.lowPass; } console.log("Accel Options:", options); wire.writeBytes(register.DATA_FORMAT, [command.normal_mode], function(err) { console.log("Initialize Error Data Format:", err); deviceReady = false; }); wire.writeBytes(register.POWER_CTL, [command.measurement_mode], function(err) { console.log("Initialize Error POWER_CTL:", err); deviceReady = false; }); deviceReady = true; calibrate(); };
SetLed: function(state, callback){ var s = value.OFF; if ( state ){ s = value.ON; } wire.writeBytes(command.SET_LED, [s], function(err) { callback(err); }); },
// Send temperature measurement command(0xF3) // The exe0 command says to return the temp measured when the humidity was read. p21 function sendTempCmd() { // logger.debug("Sending read temperature command..."); sensor.writeBytes(0xe0, [1], function(err) { if(err) { logger.debug("writeBytes: 0xe0: " + err); } readTemp(); // No need to wait since it was computed with humidity }); }
// Writes the data to the 8x8 Matrix function writeLED(){ wire.writeBytes(0x00, [green[a], red[b]], a++, b++); // Row 1 wire.writeBytes(0x02, [green[a], red[b]], a++, b++); // Row 2 wire.writeBytes(0x04, [green[a], red[b]], a++, b++); // Row 3 wire.writeBytes(0x06, [green[a], red[b]], a++, b++); // Row 4 wire.writeBytes(0x08, [green[a], red[b]], a++, b++); // Row 5 wire.writeBytes(0x0A, [green[a], red[b]], a++, b++); // Row 6 wire.writeBytes(0x0C, [green[a], red[b]], a++, b++); // Row 7 wire.writeBytes(0x0E, [green[a], red[b]], a++, b++); // Row 8 a=0; // Reset 'a' variable b=0; // Reset 'b' variable }
return new Promise(function (res, rej) { //console.log(wire, writeByte, ) wire.writeBytes(commandObj.command, commandObj.body, function (err) { if (err) { rej(err); return; } res(); }); });
function (callback) { matrix.writeBytes(i, [0x00], function (error) { if (error) { callback("in writeBytes: " + error); } else { i++; callback(null); } }); },
SetMotors: function(power, callback){ if ( power < 0 ){ if ( ( power * -1 ) > limit.PWM_MAX ){ power = ( limit.PWM_MAX * -1 ); } power = Math.ceil( ( power / 100 ) * limit.PWM_REV_MAX ); wire.writeBytes(command.SET_ALL_REV, [power], function(err) { callback(err); }); } else { if ( power > limit.PWM_MAX ){ power = limit.PWM_MAX; } power = Math.floor( ( power / 100 ) * limit.PWM_MAX ); wire.writeBytes(command.SET_ALL_FWD, [power], function(err) { callback(err); }); } },
SetCommsFailsafe: function(state, callback){ var s = value.OFF; if ( state ){ s = value.ON; } wire.writeBytes(command.SET_FAILSAFE, [s], function(err) { if ( err ){ callback(err); } }); },
SetEpoIgnore: function(state, callback){ var s = value.OFF; if ( state ){ s = value.ON; } wire.writeBytes(command.SET_EPO_IGNORE, [s], function(err) { if ( err ){ callback(err); } }); },
// Randomly spawns 8 red blocks on the 8x8 matrix function spawnEnemies(){ for(var i=0;i<enemies;i++){ enemyX=Math.floor((Math.random()*7)+1); enemyY=i; if(enemyX == posx && enemyY == posy){ spawnEnemies(); } wire.writeBytes((enemyY*2)+1, [Math.pow(2,enemyX)]); } }
// Checks to see if cursor hit a point value function checkPoints(){ if(posx === pointX && posy === pointY && wire.address === location){ points += 10; console.log(points + " points."); spawnEnemies(); spawnPoints(); wire.writeBytes(posy*2, [Math.pow(2,posx)]); clearInterval(timing); time = time-10; timing = setInterval(gameStart, time); } }
SetNewAddress: function(newAddress, callback){ wire.writeBytes(command.SET_I2C_ADD, [newAddress], function(err) { if ( err ){ callback(err); } wire.setAddress(newAddress, function(err) { if ( err ){ callback(err); } }); }); }
/********************************************************* * Functions used to check the (x,y) coordinates of the * * cursor and move the cursor along the (x,y) axis. * *********************************************************/ /*Checks the x coordinates and updates the LED Matrix If the analog value is >0.9 it moves right, if its <0.1 it moves left */ function checkX() { var xCoord; xCoord=b.analogRead('P9_36'); if(xCoord > 0.95){ if(posy === pointY && wire.address === location){ wire.writeBytes(posy*2, [0]); posx+=1; wire.writeBytes(posy*2, [Math.pow(2,posx)+Math.pow(2,pointX)]); } else{ posx+=1; wire.writeBytes(posy*2, [Math.pow(2,posx)]); } } if(xCoord < 0.05){ if(posy === pointY && wire.address === location){ wire.writeBytes(posy*2, [0]); posx -=1; wire.writeBytes(posy*2, [Math.pow(2,posx)+Math.pow(2,pointX)]); } else{ posx -=1; wire.writeBytes(posy*2, [Math.pow(2,posx)]); } } return posx; }
function processData(line) { var i; // for(i=0; i<line.length; i+=2) { // console.log("processData: %d: %s, %s", i, line[i].toString(16), line[i+1].toString(16)); // } line[0] ^= 1<<y; // Toggle green LED line[1] ^= 1<<y; // Toggle red LED // for(i=0; i<line.length; i+=2) { // console.log("processData: %s, %s", line[i].toString(16), line[i+1].toString(16)); // } display.writeBytes(2*x, line, done); }