Skip to content

Instantly share code, notes, and snippets.

@bigjosh
bigjosh / Blinks Send and Receive Test
Last active September 1, 2017 18:22 — forked from jbobrow/Blinks Send and Receive Test
Quick test for latest Arduino based Blinks API
@bigjosh
bigjosh / AVR watchdog delay
Created August 8, 2017 00:28
Code to make a very low power delay by setting the watchdog timer and then sleeping.
// Goto bed, will only wake up on button press interrupt (if enabled) or WDT
static void deepSleep(void) {
set_sleep_mode( SLEEP_MODE_PWR_DOWN );
sleep_enable();
sleep_cpu(); // Good night
}
// Don't do anything, just the interrupt itself will wake us up
@bigjosh
bigjosh / breath.c
Last active June 20, 2017 19:31
Breathing LED for Arduino or AVR C. Adafuit profile. Data in flash.
#include <avr/pgmspace.h>
const PROGMEM uint8_t breath_data[] = {
64, 68, 72, 76, 81, 85, 90, 95, 100, 105, 110, 116, 121, 127, 132, 138,
144, 150, 156, 163, 169, 176, 182, 189, 196, 203, 211, 218, 225, 233, 241, 249,
255, 249, 241, 233, 225, 218, 211, 203, 196, 189, 182, 176, 169, 163, 156, 150,
144, 138, 132, 127, 121, 116, 110, 105, 100, 95, 90, 85, 81, 76, 72, 68
};
#define BREATH_LEN (sizeof( breath_data) / sizeof( *breath_data ))
/*
* ATTINY85-LED-Boost.c
* Full article at
* http://wp.josh.com/2017/03/20/blinking-blue-powering-a-3-7-volt-blue-led-from-a-2-4-volt-coin-cell-with-a-0-02-charge-pump
*
*/
#include <avr/io.h>
#define F_CPU 1000000 // 1MHz, default for 8MHz internal osc and clkdiv8
@bigjosh
bigjosh / gist:002dffefb082828348e07397289f8587
Created February 16, 2017 03:44
Arduino sketch that will put a DS3231 time keeping chip into a low power mode where it outputs a 1Hz square wave (pull up needed)
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
#define DS_REG_CR (0x0e) // Control Reg
#define DS_REG_SR (0x0f) // Status Reg
// Pins connected to the DS2321
// We want to know these so we can put them HI_Z when not talking to the board to get a real power measurement.
#define D_SCLK A5
#define D_SDAT A4
@bigjosh
bigjosh / TileHAL.h
Created January 12, 2017 22:19
Proposed hardware abstraction layer for the tile.
/*
* AutomaTileHAL.h
*
* Created: 1/6/2016 11:56:26
* Proposed hardware abstraction layer for the tile.
*
* This layer only handles the bare minimum for interfacing with the hardware, all normal
* gam-designer-facing functionality is in a portable library that interacts with this HAL.
*
*
@bigjosh
bigjosh / AvrSerialPin
Created January 2, 2017 21:51
Output a byte on a pin as serial data. Good for debugging, especially if your scope as serial decode.
// Print as a serial bit stream on PB2 - Each bit is 17us, just about 38400 baud - LSB first - for debugging.
void sprint( uint8_t x ) {
DDRB |= _BV(2);
PORTB |= _BV(2); // Idle on serial port
_delay_us(22);
PORTB &= ~_BV(PORTB2); // start bit
@bigjosh
bigjosh / main.c
Last active May 13, 2018 21:19
PWM Motor control code for AIRBOAT running on ATTINY10
/*
* Attiny10 AIRBOAT PWM Motor control code
*
* Created: 12/2/2016 6:17:47 PM
* Author : josh
*/
#include <avr/io.h>
#include <util/delay.h>
root@beaglebone:~# iw list
Wiphy phy0
max # scan SSIDs: 4
max scan IEs length: 2257 bytes
Retry short limit: 7
Retry long limit: 4
Coverage class: 0 (up to 0m)
Device supports RSN-IBSS.
Supported Ciphers:
* WEP40 (00-0f-ac:1)
@bigjosh
bigjosh / TimerShotTimer1B.ino
Created September 1, 2016 02:42
Code to generate a one-shot pulse on AVR Timer1B by Nevell Greenough, N2GX. More info about this program is here... http://wp.josh.com/2015/03/05/the-perfect-pulse-some-tricks-for-generating-precise-one-shots-on-avr8/
// **************** TimerShot for Timer 1B *********************
// More info about this program is here...
// http://wp.josh.com/2015/03/05/the-perfect-pulse-some-tricks-for-generating-precise-one-shots-on-avr8/
// Demo of a technique to generate various precise one shot pulses using
// timer 1 module on an AVR. This demo code version is writen for an Arduino Uno or Mega2560 for the
// the Timer1 moudule, but this technique should would on other 16-bit AVR timers on Mega2560.
// Original code by Josh Levine, hack by N2GX 8/30/2016.
// Long-pulse working solution for TIMER 1B One-Shot, edited from Josh's Timer2 code and a partial Timer3 solution