//Toggle the output pin based on the input pin function toggle(){ if(b.digitalRead(leader)){ b.digitalWrite(follower, b.HIGH); } else { b.digitalWrite(follower, b.LOW); } }
// One cycle that gets called repeatedly function cycleChangeState() { // Heater 1 duty cycle switching if ( buts[0] > 0) { b.digitalWrite(ssr[0], 1 ); io.sockets.emit('btnState', {ssr:0, state:1 }); if ( ontime1 == 100 ) { console.log("H1 is full on") } else { console.log("H1 is cycling ON ", ontime1/20*1000); setTimeout( function myCycle () { b.digitalWrite(ssr[0], 0 ); io.sockets.emit('btnState', {ssr:0, state:0 }); console.log("H1 turned OFF"); } , ontime1/20*1000); // percentage / time basis in dcTimer (5 sec) * time(ms) } } // Heater 2 duty cycle switching if ( buts[1] > 0) { b.digitalWrite(ssr[1], 1 ); io.sockets.emit('btnState', {ssr:1, state:1 }); if ( ontime2 == 100 ) { console.log("H2 is full on") } else { console.log("H2 is cycling ON ", ontime2/20*1000); setTimeout( function myCycle () { b.digitalWrite(ssr[1], 0 ); io.sockets.emit('btnState', {ssr:1, state:0 }); console.log("H2 turned OFF"); } , ontime2/20*1000); } } }
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"); } } }
function printStatus2(x2) { if(x2.value ==1) { b.digitalWrite(LED2,b.HIGH); if(z<number-1)z=z+1; } if(x2.value ==0) { b.digitalWrite(LED2,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]]); } } }
socket.on('pin', function (data) { var len = activePins.length; var duplicate; for (var i=0; i<len; i++){ if (data.id === activePins[i].id){ duplicate = true; } } if (duplicate !== true){ activePins[len] = {id: data.id, type: data.type, subType: data.subType, num: data.num}; } if (data.type === 'usr leds' || data.subType != "input" && data.subType != "pwm"){ b.pinMode(data.id,b.OUTPUT); if (data.power === "on"){ if (data.freq !== 0){ data.state = data.state ? 0 : 1; b.digitalWrite(data.id, data.state); } else{ b.digitalWrite(data.id, 1); } } else{ b.digitalWrite(data.id, 0); } } else if (data.subType === "pwm"){ if (data.power === "on"){ b.analogWrite(data.id, data.freq); } else {b.analogWrite(data.id, 0);} } });
function finishWork() { //init vars RECV1_TIME = 0; RECV2_TIME = 0; START_TIME = 0; //turn off the receiver and sender b.digitalWrite(INHIBIT1, b.HIGH); b.digitalWrite(INHIBIT2, b.HIGH); b.digitalWrite(ULTRASONIC_OUTPUT, b.LOW); b.digitalWrite(CUT_OFF, b.HIGH); //release interval console.log("finishWork:", timer); clearInterval(timer); timer = null; console.log("finishWork:", timer); //turn off the led b.digitalWrite(STARTLED, b.LOW); console.log("finishWork!"); }
function setPins(dir1, dir2, pwm) { b.digitalWrite(dirPin1, dir1); b.digitalWrite(dirPin2, dir2); // PWM value must be between 0 and 1 b.analogWrite(pwmPin, RxBotics.Math.constrain(Math.abs(pwm), 0, 1)); }
var server = http.createServer(function (req, res) { // server code var path = url.parse(req.url).pathname; console.log("path: " + path); // console.log("req: " + util.inspect(req)); // console.log("res: " + util.inspect(req)); res.write("<html>"); if(path === '/on') { b.digitalWrite(LED, 1); res.write("LED on<br>"); } else if (path === '/off') { b.digitalWrite(LED, 0); res.write("LED off<br>"); } else if (path === '/toggle') { b.digitalWrite(LED, ~b.digitalRead(LED)); res.write("LED toggle<br>"); } var params = util.inspect(qs.parse(url.parse(req.url).query)); console.log(params); res.write(params); res.write("</html>"); res.end(); });
function operation(){ state = state ? 0 : 1; b.digitalWrite(in1, state); b.digitalWrite(in2, state); b.digitalWrite(in3, state); b.digitalWrite(in4, state); }
setInterval(update7Seg, 100); // Call update7Seg() every 100ms /* * Define functions */ function update7Seg() { digit = (digit + 1) % 10; // Increment and wrap the digit (0-9) // Shift out the character LED pattern b.shiftOut(S_DATA, S_CLOCK, b.MSBFIRST, segments[digit]); b.digitalWrite(S_LATCH, b.HIGH); b.digitalWrite(S_LATCH, b.LOW); }
function checkButton(x) { if(x.value == 1 || !are10secondsElapsed){ b.digitalWrite('P8_13', b.HIGH); } else{ b.digitalWrite('P8_13', b.LOW); } }
socket.on('output', function (data) { console.log(data); if (data == 'on'){ b.digitalWrite(output, b.HIGH); } else { b.digitalWrite(output, b.LOW); } });
function receive() //the version for short distance { GA_NO = 0; setGain(GA_NO); //setInterval(timerIsr, GainTime[GA_NO]); b.digitalWrite(INHIBIT1, b.LOW); b.digitalWrite(INHIBIT2, b.LOW); }
socket.on('greenLED', function (data) { if(data.state == 1) { console.log("green on"); b.digitalWrite(greenLED, b.HIGH); } else { console.log("green off"); b.digitalWrite(greenLED, b.LOW); } });
socket.on('yellowLED', function (data) { if(data.state == 1) { console.log("yellow on"); b.digitalWrite(yellowLED, b.HIGH); } else { console.log("yellow off"); b.digitalWrite(yellowLED, b.LOW); } });
var s = function() { b.digitalWrite('USR0', a); b.digitalWrite('USR1', ~a); b.digitalWrite('USR2', a); b.digitalWrite('USR3', ~a); a=~a; //setInterval(s(t), t*100 ); }
// check to see if input it pressed, maybe eventually incoporate frequency function checkPin(x){ if(x.value == 1){ b.digitalWrite(outputPin, b.HIGH); // io.emit('outputStatus',"on"); } else{ b.digitalWrite(outputPin, b.LOW); // io.emit('outputStatus',"off"); } }
function recv1() { RECV1_TIME = new Date().getTime(); var d1 = (RECV1_TIME - START_TIME); b.digitalWrite(INHIBIT1, b.HIGH); //turn off the receiver delay(PLUSE * 2); b.digitalWrite(INHIBIT1, b.LOW); //wait and turn on again console.log("recv1", d1); }
socket.on('ledBlue', function(data) { if (data == 'on') { b.digitalWrite(ledBlue,1); //console.log("Blue is On"); } else if (data == 'off') { b.digitalWrite(ledBlue,0); //console.log("Blue is Off"); } });
socket.on('redLED', function (data) { if(data.state == 1) { console.log("red on"); b.digitalWrite(redLED, b.HIGH); } else { console.log("red off"); b.digitalWrite(redLED, b.LOW); } });
function recv2() { RECV2_TIME = new Date().getTime(); var d2 = (RECV2_TIME - START_TIME); b.digitalWrite(INHIBIT2, b.HIGH); delay(PLUSE * 2); b.digitalWrite(INHIBIT2, b.LOW); console.log("recv2", d2); }
bone.attachInterrupt(DRAW_BUTTON, true, bone.FALLING, function (x) { if (!locked) { draw = !draw; } if (draw) { bone.digitalWrite(DRAW_LED, bone.HIGH); } else { bone.digitalWrite(DRAW_LED, bone.LOW); } });
function swappy() { if (out == 0) { b.digitalWrite('P9_12', b.LOW, 7); out = 1; } else { b.digitalWrite('P9_12', b.HIGH, 7); out = 0; } }
function Startlights() { var i; for (i = 1; i < 4; i++) { b.pinMode(pins[i], 'out'); b.digitalWrite(pins[i], 1); delay (100); } for (i = 3; i >= 0; i--) { b.digitalWrite(pins[i], 0); delay (100); } }
socket.on('led', function (data) { console.log(data); if (data == 'on'){ bs.digitalWrite("USR3", bs.HIGH); socket.emit('ledstatus', 'on'); socket.broadcast.emit('ledupdate', 'on'); }else{ bs.digitalWrite("USR3", bs.LOW); socket.emit('ledstatus', 'off'); socket.broadcast.emit('ledupdate', 'off'); } });
socket.on('speechAction',function(data){ console.log(data.speech); var speech = data.speech.toLowerCase(); if(speech.search('yellow on') > -1){ console.log('yellow on'); b.digitalWrite(yellowLED, b.HIGH); } if(speech.search('yellow off') > -1){ console.log('yellow off'); b.digitalWrite(yellowLED, b.LOW); } });
global.setup = function() { b.analogWrite('P9_14', 0.2); b.pinMode('P9_14', b.OUTPUT); b.digitalWrite('P9_14', false); b.digitalWrite('P9_14', true); console.log(JSON.stringify(b.getPinMode('P9_16'))); b.pinMode('P9_16', b.OUTPUT); console.log(JSON.stringify(b.getPinMode('P9_16'))); b.digitalWrite('P9_16', false); console.log(JSON.stringify(b.getPinMode('P9_16'))); b.digitalWrite('P9_16', true); console.log(JSON.stringify(b.getPinMode('P9_16'))); };
b.main=function(){ Motor.initPins(); var blueMotor = new Motor(1, Motor.motor1pin1, Motor.motor1pin2, 0); var yellowMotor = new Motor(1, Motor.motor2pin1, Motor.motor2pin2, 0); b.analogWrite(blueMotor.fowardPin, 0.5, 1000, callback); b.analogWrite(yellowMotor.fowardPin, 0.5, 1000, callback); for (var i = 0; i < 100000; i++) { b.print("The value of i is: " + i); } b.digitalWrite(blueMotor.forwardPin, b.LOW); b.digitalWrite(yellowMotor.forwardPin, b.LOW); };
function moveRight(b_state) { // console.log('right'); // console.log('state value ' + b_state.value); if ((y<(size-1) && (b_state.value==0))) { y++; grid[x][y] = 'x'; for (i=0; i<size; i++){ console.log(grid[i]); } console.log('\n'); b.digitalWrite(LED_right, b.HIGH); } if (b_state.value == 1) b.digitalWrite(LED_right, b.LOW); }
function moveUp(b_state) { // console.log('up'); // console.log('state value ' + b_state.value); if ((x>0) && (b_state.value == 0)) { x--; grid[x][y] = 'x'; for (i=0; i<size; i++){ console.log(grid[i]); } console.log('\n'); b.digitalWrite(LED_up, b.HIGH); } if (b_state.value == 1) b.digitalWrite(LED_up, b.LOW); }