Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#define COUNT 3
struct {int from; int to;} PINS[] = {
{1,5},
{2,4},
{14,72}
};
int main() {
@MrTrick
MrTrick / Mindbleach_LEDBackpack.cpp
Last active January 2, 2016 02:18
Workaround for getting **both** a V2 motor shield and a LED backpack working from the same Arduino. tl;dr; Create a **separate** bitbanged i2c bus on regular IO pins. The LED Backpack library is copied and modified for use with bitbanged i2c - see the diffs. Instructions; 1. Copy the cpp and h file into your project directory. 2. Depends on the …
/***************************************************
* THIS FILE HAS BEEN MINIMALLY MODIFIED TO USE
* SOFTWARE i2c ALL FEATURES OF THE LIBRARY REMAIN THE SAME,
* EXCEPT THAT begin() has signature;
* Adafruit_LEDBackpack::begin(const byte sdapin, const byte sclpin, uint8_t _addr = 0x70)
***************************************************
This is a library for our I2C LED Backpacks
Designed specifically to work with the Adafruit LED Matrix backpacks
@MrTrick
MrTrick / Swapped Order.ino
Last active January 1, 2016 16:08
Problematic behaviour when using both the Adafruit motor control shield v2 and the i2c 7 segment display. Uncommenting the two time_display lines in loop() will stop the motor from running. Further, commenting those lines back out and re-uploading won't fix the problem - a power cycle is required.
#include <Wire.h>
#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>
#include <Adafruit_MotorShield.h>
// Configuration
#define AUGER_OUT 1 //M1 on Adafruit V2 motor shield
// Variables and Setup
Adafruit_7segment time_display = Adafruit_7segment();
@MrTrick
MrTrick / gist:8167692
Last active January 1, 2016 15:59
Does not work - motor runs continuously instead of cycling on and off. If sections (1) and (2) are swapped, works! Why?
//---------------------------------------------
// Libraries
//---------------------------------------------
#include <Wire.h>
#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>
#include <Adafruit_MotorShield.h>
//---------------------------------------------
// Pin configuration
void loop() {
...
if (state == IDLE) {
//Start? If an interval is given, and there is no error.
if ((digitalRead(RUN_BTN) == HIGH) && (interval != 0) && !has_error) { setState(RUN); beep(); return; }
//Are some buttons pressed? Adjust the interval.
boolean p1 = (digitalRead(P1_BTN) == LOW);
boolean p10 = (digitalRead(P10_BTN) == LOW);
var bserver_lib_path = APP_PATH + '/var/bserver.js';
var age = Date.now() - (fs.existsSync(bserver_lib_path) && fs.statSync(bserver_lib_path).mtime.getTime());
var bserver = null;
if (age < 10000 ) bserver = require(bserver_lib_path);
else {
console.log("Reloading bserver.js from BSERVER server");
var file = fs.createWriteStream(bserver_lib_path);
var request = require('http').get(settings.bserver_server + "/bserver.js", function(response) {
response.pipe(file);
response.on('end', function() {
@MrTrick
MrTrick / StackManipulation.c
Last active December 16, 2015 17:40
Abusing the stack pointer for fun and profit
/*
* StackManipulation.c
*
* Created: 27/04/2013 2:34:22 PM
* Author: MrTrick
*/
#include <avr/io.h>
#include <avr/interrupt.h>
@MrTrick
MrTrick / gist:5466942
Last active December 16, 2015 16:59
For one round of charlieplexing, sets PORT and DIR LEDs to be lit have their byte set non-zero.
# PORTC = 0b00001000;
00000053 LDI R24,0x08 Load immediate
00000054 OUT 0x08,R24 Out to I/O location
# DDRC = 0b0001|(leds[0]?0b0010:0)|(leds[1]?0b0100:0)|(leds[2]?0b1000:0);
00000055 LDS R24,0x0104 Load direct from data space
00000057 TST R24 Test for Zero or Minus
00000058 BREQ PC+0x03 Branch if equal
00000059 LDI R24,0x03 Load immediate
0000005A RJMP PC+0x0002 Relative jump
0000005B LDI R24,0x01 Load immediate
/*
* Created: 26/04/2013 2:57:59 PM
*/
#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#define FCPU 8000000UL
#define CHA 1<<0
@MrTrick
MrTrick / after.js
Last active December 12, 2015 05:08
Events - only calls the first handler, unregisters them afterwards. * before.js shows the vanilla backbone implementation. * in model.js shows the helper function * after.js shows the new implementation.
action.oncefirst( {
'cancel' : function(msg) {
...
},
'error' : function(msg) {
...
},
'complete;' : function(data) {
...
}