Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
laclefyoshi / sketch_websocket.py
Created December 25, 2010 04:32
WebSocket server for communicating Web browser and Arduino
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2010/12/24
import tornado.httpserver
import tornado.ioloop
import tornado.web
@laclefyoshi
laclefyoshi / sketch.html
Created December 25, 2010 04:34
Web page for drawing a picture and sending the drawing data to WebSocket server
<!DOCTYPE html>
<html lang="jp" xml:lang="jp">
<head>
<meta charset="utf-8">
<title>Sketch</title>
<style>
body{
margin: 0px; padding: 0px;
}
canvas {
@laclefyoshi
laclefyoshi / googleearth.py
Created January 1, 2011 08:12
Controlling Google Earth for Mac
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2011/01/01
import subprocess
import time
@laclefyoshi
laclefyoshi / gist:769513
Created January 7, 2011 14:32
DNS server with Arduino and EthernetShield
// -*- mode: c++ -*-
/**
Copyright: (c) SAEKI Yoshiyasu
License : MIT-style license
<http://www.opensource.org/licenses/mit-license.php>
last updated: 2011/01/12
**/
#include <SPI.h>
@laclefyoshi
laclefyoshi / gist:790835
Created January 22, 2011 03:44
DNS server like dnsmasq with Arduino and EthernetShield
// -*- mode: c++ -*-
/**
Copyright: (c) SAEKI Yoshiyasu
License : MIT-style license
<http://www.opensource.org/licenses/mit-license.php>
last updated: 2011/01/21
**/
#include <SPI.h>
#include <Ethernet.h>
@laclefyoshi
laclefyoshi / gist:800358
Created January 28, 2011 15:07
Arduino FlexiTimer2
#include <FlexiTimer2.h>
#define LedPin1 10
#define LedPin2 9
void blink1() {
digitalWrite(LedPin1, !digitalRead(LedPin1));
}
void blink2() {
digitalWrite(LedPin2, !digitalRead(LedPin2));
@laclefyoshi
laclefyoshi / gist:800363
Created January 28, 2011 15:12
Arduino Metro
#include <Metro.h>
#define LedPin1 10
#define LedPin2 9
Metro ledMetro1 = Metro(1000);
Metro ledMetro2 = Metro(2000);
void setup() {
pinMode(LedPin1, OUTPUT);
@laclefyoshi
laclefyoshi / gist:800391
Created January 28, 2011 15:30
Arduino protothread
#include <pt.h>
#define LedPin1 12
#define LedPin2 11
static struct pt pt1, pt2;
static int protothread1(struct pt *pt) {
static unsigned long timestamp = 0;
PT_BEGIN(pt);
@laclefyoshi
laclefyoshi / gist:800403
Created January 28, 2011 15:35
Arduino protothread + Metro
#include <pt.h>
#include <Metro.h>
#define LedPin1 12
#define LedPin2 11
#define LedPin3 10
#define LedPin4 9
static struct pt pt1, pt2;
@laclefyoshi
laclefyoshi / mmode_timer555.py
Created February 5, 2011 04:16
Monostable mode of 555 timer
def mTimeCalculate(info):
r1 = info["r1"]
c = info["c"]
print "R1: %d, C: %f¥n¥tTime: %f(sec)¥n" % (r1, c, r1 * c * math.log(3))
# math.log(3) = 1.1
def mResisterCalculate(info):
t = info["time"]
c = info["c"]