Skip to content

Instantly share code, notes, and snippets.

@wgbartley
wgbartley / smartDingDong.cpp
Created March 7, 2014 22:20
A simple sketch for detecting a button press (for example, a doorbell) that calls a web page to send a text message. The onboard RGB LED will be red when nothing is happening. It turns green as it makes the web request, and then turns blue for 1 second after the request.
int ddl = 0; // Ding dong last millis()
int btnpin = D0; // "Button" pin
const int ddd = 15000; // Time until button can be activated again
void setup() {
pinMode(btnpin, INPUT_PULLUP);
RGB.control(true);
}
@wgbartley
wgbartley / doorbell2SMS.cpp
Last active August 29, 2015 13:57
Doorbell-to-SMS
/**
* This is a simple "sketch" that calls a web page when a button is pressed. It is a proof-of-concept
* for my boss and hastily written in about 2 hours. The remote URL is a PHP script that handles
* making the API calls to a remote SMS-messaging service.
*
* I'm sure it could make use of interrupts somehow, but I'm not sure how off the top of my head.
*
* It uses the onboard RGB LED as status display:
* - Red = Waiting to be pressed
* - Green = Making HTTP request
@wgbartley
wgbartley / DHT22.cpp
Last active August 29, 2015 13:57
Less Blocking DHT22 Library for Spark Core
#include "DHT22.h"
DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
_pin = pin;
_type = type;
_count = count;
firstreading = true;
_next_read_millis = 0;
_next_read_step = 1;
}
@wgbartley
wgbartley / DHT.cpp
Created April 26, 2014 05:09
Spark Sensor Madness with Classes
#include "DHT.h"
DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
_pin = pin;
_type = type;
_count = count;
firstreading = true;
}
@wgbartley
wgbartley / uptime.ino
Created May 26, 2014 19:45
Spark Uptime Test
char srvIP[] = "198.199.86.22";
char srvHost[] = "spark.wgb.me";
int srvPort = 80;
char srvPath[] = "/logger/?l=uptime-test";
void setup() {
delay(5000);
pinMode(D7, OUTPUT);
@wgbartley
wgbartley / angry-bird.ino
Created June 7, 2014 00:02
Spark-Powered Angry Bird Swimmer
// D0 = Angle Down
// D1 = Angle Up
// D2 = Left
// D3 = Right
int pinLeft = D2;
int pinRight = D3;
int pinDown = D0;
int pinUp = D1;
@wgbartley
wgbartley / webcam-viewer.py
Created July 14, 2014 15:37
Grab latest webcam picture and display it on a monitor from the command-line
#!/usr/bin/python
import pygame, httplib, io
from pygame.locals import *
from PIL import Image, ImageFont, ImageDraw
from time import time, sleep, strftime, localtime
# Screen setup
print "Press ctrl+c"
display = pygame.display
@wgbartley
wgbartley / launch_webs.sh
Last active August 29, 2015 14:08
Docker web container launcher
#!/bin/bash
for d in $(find www-enabled/ -mindepth 1 -maxdepth 1 -type l); do
bn=`basename $d`
aliases_arr=($bn)
aliases_i=1
# Check if the container is already running
is_running=`docker ps -f status=running | grep "$bn" | wc -l`
@wgbartley
wgbartley / spark-web-ide-memory-tracker.html
Created November 12, 2014 23:18
Spark Web IDE Memory Tracker
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://benpickles.github.io/peity/jquery.peity.js"></script>
<script type="text/javascript">
@wgbartley
wgbartley / gist:b9f1f016b0e223699da0
Last active August 29, 2015 14:23
Discourse Forum User Post Alert
/**
* This monitors a Discourse forum for postings by a particular user.
* I stopped just shy of figuring out how to publish an event to a
* Particle device PubSub stream.
**/
var https = require('https'),
cp = require('child_process'),
xmlParseString = require('xml2js').parseString;