Skip to content

Instantly share code, notes, and snippets.

View jamesabruce's full-sized avatar

James Bruce jamesabruce

  • Cornwall, UK
View GitHub Profile
#include <NewPing.h>
//Tell the Arduino where the sensor is hooked up
NewPing sonar(12, 13);
long inches;
void setup() {
//Activate the serial monitor so you can see the output of the sensor
Serial.begin(9600);
<form data-fv-framework="bootstrap" novalidate="novalidate" class="fv-form fv-form-bootstrap"><button type="submit" class="fv-hidden-submit" style="display: none; width: 0px; height: 0px;"></button>
<div class="items">
<div class="item">
<input type="hidden" name="topics[0][type]" value="category">
<input type="hidden" name="topics[0][id]" value="4893">
<input type="hidden" name="topics[0][checked]" value="0">
<label><div class="checker"><span><input name="topics[0][checked]" value="1" type="checkbox"></span></div><span>Smart Home</span></label>
</div>
<div class="item">
<input type="hidden" name="topics[1][type]" value="post_tag">
// how long each led stays on for
int delayTime = 1;
//how long between each
int charBreak = 3;
//how long to wait after the message is finished before it repeats
int resetTime = 20;
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
@jamesabruce
jamesabruce / detect.py
Created August 19, 2015 11:53
OpenHAB on Raspberry Pi Tutorial: Detect User Presence via Bluetooth, report to RESTful OpenHAB interface
#!/usr/bin/python
import bluetooth
import time
import requests
from requests.exceptions import ConnectionError
payload =''
while True:
@jamesabruce
jamesabruce / detect.py
Created July 14, 2015 16:52
Detect user through Bluetooth demo, Python
#!/usr/bin/python
import bluetooth
import time
while True:
print "Checking " + time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime())
result = bluetooth.lookup_name('78:7F:70:38:51:1B', timeout=5)
if (result != None):
print "User present"
@jamesabruce
jamesabruce / Philips Hue Candle Effect
Created April 4, 2015 07:22
High speed, flickering candle bulb effect for any number of Philips Hue bulbs
set HUB to "192.168.1.216" --change for your bridge IP
set USER to "newdeveloper"
repeat
repeat with bulb from 1 to 2 -- Change if you have more bulbs or want to use a subset
set hue to (random number from 5000 to 12750)
set sat to (random number from 150 to 255)
set bri to (random number from 50 to 255)
set transitiontime to (random number from 1 to 3) -- Increase range for slower transitions
set query to "{\"sat\":" & sat & ",\"hue\":" & hue & ",\"bri\":" & bri & ",\"transitiontime\":" & transitiontime & "}"
set command to "curl --request PUT --data '" & query & "' http://" & HUB & "/api/" & USER & "/lights/" & bulb & "/state/ --connect-timeout 5"
/*
Lighting Cloud Mood Lamp By James Bruce
View the full tutorial and build guide at http://www.makeuseof.com/
Sound sampling code originally by Adafruit Industries. Distributed under the BSD license.
This paragraph must be included in any redistribution.
*/
#include <Wire.h>
#include "FastLED.h"
/*
* Sunrise Alarm Clock and Night Light by James Bruce
* http://duinobits.com
* Initial setup requires you to reset the Arduino sometime in the evening.
* Set the hoursUntilSunrise relative to this time.
* eg, if you reset at 10pm, and want the sunrise to start at 6:30am,
* the value should be 8.5 - this will then be automatically changed to minutes for internal clock to function
*
*/
@jamesabruce
jamesabruce / Officelight_accessory.js
Last active September 5, 2018 19:20
HAB-NodeJS accessory for MakeUseOf Wi-Fi light tutorial
// MQTT Setup
var mqtt = require('mqtt');
console.log("Connecting to MQTT broker...");
var mqtt = require('mqtt');
var options = {
port: 1883,
host: '192.168.1.99',
clientId: 'MakeUseOf Wifi Light'
};
var client = mqtt.connect(options);
@jamesabruce
jamesabruce / neomatrix_pixel_display.ino
Created January 22, 2015 17:55
Sample code for working with the giant LED screen described at MakeUseOf.com, using Adafruit Neomatrix and GFX libraries
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define XSIZE 15
#define YSIZE 14
#define PIN 6
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(XSIZE, YSIZE, PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +