Skip to content

Instantly share code, notes, and snippets.

@wgbartley
wgbartley / proxy.php
Last active December 18, 2017 16:30
Spark PHP Proxy
<?php
// Set your access token here
define('ACCESS_TOKEN', 'your_access_token_here');
// Make sure we have an HTTP_ACCEPT header,
// and if so, make it lower-case for easier string matching
if(isset($_SERVER['HTTP_ACCEPT']))
$_SERVER['HTTP_ACCEPT'] = strtolower($_SERVER['HTTP_ACCEPT']);
else
@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 / elapsedMillis.h
Created April 24, 2014 03:28
Simple Spark Core firmware for reading temperature from TMP36 and light from an LDR
/* Elapsed time types - for easy-to-use measurements of elapsed time
* http://www.pjrc.com/teensy/
* Copyright (c) 2011 PJRC.COM, LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
@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 / 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 / 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 / Configuration.h
Last active December 5, 2015 06:24
Configuration.h for my Prusa i3
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
// This configuration file contains the basic settings.
// Advanced settings can be found in Configuration_adv.h
// BASIC SETTINGS: select your board type, temperature sensor type, axis scaling, and endstop configuration
//===========================================================================
//============================= DELTA Printer ===============================
//===========================================================================
@wgbartley
wgbartley / Spark-DS18B20.pde
Last active January 2, 2016 12:09
Class to read temperature from DS18B20 sensor attached to a Spark Core
#ifndef OneWire_h
#define OneWire_h
#include <inttypes.h>
// you can exclude onewire_search by defining that to 0
#ifndef ONEWIRE_SEARCH
#define ONEWIRE_SEARCH 1
#endif
// You can exclude CRC checks altogether by defining this to 0
@wgbartley
wgbartley / Spark-DHT22.pde
Last active November 20, 2016 17:09
Class for reading DHT22 values on a Spark Core
#define MAXTIMINGS 85
#define cli noInterrupts
#define sei interrupts
#define DHT11 11
#define DHT22 22
#define DHT21 21
#define AM2301 21
@wgbartley
wgbartley / Spark-Thermistor.pde
Last active January 2, 2016 12:09
Basic class for reading thermistor values on a Spark Core
#include <math.h>
class Thermistor {
private:
int _pin;
int _resistor;
int _temp_raw;
float _temp_k;
float _temp_c;
float _temp_f;