Skip to content

Instantly share code, notes, and snippets.

View jsleeio's full-sized avatar

John Slee jsleeio

View GitHub Profile
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
lcd.begin(16,2);
}
void loop() {
PROG=blink
-include ../Makefile.simple
@jsleeio
jsleeio / usbxbee.pl
Created July 25, 2013 10:38
Requires Device::SerialPort module from CPAN
#!/usr/bin/perl -w
use strict;
use warnings;
use Device::SerialPort;
my $file = "/dev/tty.usbserial-A700fbpg";
my $ob = Device::SerialPort->new ($file) || die "Can't open $file: $!";
@jsleeio
jsleeio / timing_hackery.ino
Last active January 1, 2016 02:59
arduino timing hackery
#define print_autonamed_value(p,x) do { p.print(#x " = "); p.println(x); } while (0)
#define print_named_value(p,n,x) do { p.print(n " = "); p.println(x); } while (0)
#define time_operation(p,op,sets,counts) do { \
long mstart = millis(); \
for (long set = 0; set < sets; set++) { \
for (long count = 0; count < counts; count++) { \
op; \
} \
} \
long mend = millis(); \
@jsleeio
jsleeio / gist:8175168
Created December 29, 2013 21:35
avr-gcc adding useless (?) subi instructions, why?
// compiler commandline as below:
// avr-gcc -mmcu=attiny85 -O2 -DF_CPU=16000000L -I. -Iusbdrv -std=c99 -Wall -g -c -o main.o main.c
ISR(ADC_vect) {
adclast = ADMUX & ~_BV(ADLAR);
adcreading[adclast] = ADCH;
ADMUX = adcmux[adclast];
}
@jsleeio
jsleeio / gist:8243555
Last active January 2, 2016 03:19
Arduino - reading multiple pots asynchronously with a free-running ADC
#include "avr/interrupt.h"
uint8_t pots[4] = { 0, 0, 0, 0 };
uint16_t samples[4] = { 0, 0, 0, 0 };
const uint8_t nextpot[4] = { _BV(ADLAR) | 0b0001, _BV(ADLAR) | 0b0010, _BV(ADLAR) | 0b0011, _BV(ADLAR) | 0b0000 };
void setup() {
Serial.begin(9600);
ADMUX = _BV(ADLAR) | _BV(MUX1) | _BV(MUX0);
ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADATE) | _BV(ADIE) | _BV(ADPS0)| _BV(ADPS1) | _BV(ADPS2);
void GPS_Switch_Mode_To_NMEA(void)
{
int checkSum;
const byte magicHead[] = {
0xA0, 0xA2, // start sequence
0x00, 0x18 // payload length 0x18 = 24
};
const byte magicPayload[] = {
#define LED 13
#define NDIVIDERS sizeof(divider_outputs)
uint8_t divider_outputs[] = {
12, 11, 10, 9,
8, 7, 6, 5
};
void setup(void) {
for (uint8_t i = 0; i < NDIVIDERS; i++) {
pinMode(divider_outputs[i], OUTPUT);
#!/bin/bash
# John Slee <indigoid@gmail.com>
keep_until="heart of gold"
get_wifi_interface() {
networksetup -listallhardwareports | sed -n '/Wi-Fi$/,/^Device/ { s/.*\(en[0-9]\)$/\1/p; }'
}