Skip to content

Instantly share code, notes, and snippets.

View StuffAndyMakes's full-sized avatar

StuffAndyMakes StuffAndyMakes

View GitHub Profile
@StuffAndyMakes
StuffAndyMakes / SimpleLEDController.cpp
Created July 13, 2015 14:44
Example usage for StuffAndyMakes.com Simple LED Controller shift register breakout board
#include "Arduino.h"
#define data 8
#define clk 9
#define oe 7
#define rst 6
void pulseClock() {
digitalWrite(clk, HIGH);
digitalWrite(clk, LOW);
@StuffAndyMakes
StuffAndyMakes / SAM_LED_Controller.cpp
Created July 13, 2015 13:11
Example usage for StuffAndyMakes.com Simple LED Controller shift register breakout board
#include "mbed.h"
DigitalOut data(PTB9);
DigitalOut clk(PTB8);
DigitalOut oe(PTB10);
DigitalOut rst(PTB11);
Serial out(PTA2, PTA1);
// CRC-8 - based on the CRC8 formulas by Dallas/Maxim
// code released under the therms of the GNU GPL 3.0 license
// Found at: http://www.leonardomiliani.com/en/2013/un-semplice-crc8-per-arduino/
uint8_t SerialPacket::_crc8(const uint8_t *data, uint8_t len) {
uint8_t crc = 0x00;
while (len--) {
uint8_t extract = *data++;
for (uint8_t tempI = 8; tempI; tempI--) {
uint8_t sum = (crc ^ extract) & 0x01;
crc >>= 1;
@StuffAndyMakes
StuffAndyMakes / FreeRAM.cpp
Created May 22, 2015 16:02
Quick free available RAM function for Arduino/AVR
// found at https://learn.adafruit.com/memories-of-an-arduino/measuring-free-memory
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
@StuffAndyMakes
StuffAndyMakes / SerialPacketReceiveSnippet.cpp
Last active August 29, 2015 14:21
Snippet showing SerialPacket receiving
typedef struct {
uint8_t device;
uint8_t command;
uint32_t value;
uint64_t serial;
uint8_t ack;
} Command;
void SenderApplication::didReceiveGoodPacket(SerialPacket *p) {
Serial.println("Got good packet!");
@StuffAndyMakes
StuffAndyMakes / SerialPacketSendSnippet.cpp
Last active August 29, 2015 14:21
SerialPacket Send Example
typedef struct {
uint8_t device;
uint8_t command;
uint32_t value;
uint64_t serial;
uint8_t ack;
} Command;
void SenderApplication::didReceiveGoodPacket(SerialPacket *p) {
Serial.println("Got good packet!");
@StuffAndyMakes
StuffAndyMakes / Charlieplex20LEDs.cpp
Last active July 7, 2019 17:35
Charlieplexing 20 LEDs
// pin defines
#define A 12
#define B 11
#define C 10
#define D 9
#define E 8
#define PIN_COUNT 5
#define PIN_CONFIG 0
@StuffAndyMakes
StuffAndyMakes / printBigBinary.cpp
Created November 16, 2014 00:30
Quick Easy Binary Value Print Function
String printBigBinary( uint32_t n, int spacing ) {
int bitPosition = sizeof(n) * 8 - 1;
String bits = "";
while (bitPosition >= 0) {
bits += (n & (1UL<<bitPosition)) == (1UL<<bitPosition) ? "1" : "0";
if (bitPosition % spacing == 0) {
bits += " ";
}
bitPosition--;
}
@StuffAndyMakes
StuffAndyMakes / Chase16LEDs.ino
Created September 14, 2014 22:08
Arduino Charlieplexing Demo Project
/*
* Chase16LEDs.ino
* Description: Quick, down-n-dirty demo of Charlieplexing LEDs on an Arduino
* http://StuffAndyMakes.com
*/
#define A 12
#define B 11
#define C 10
#define D 9
@StuffAndyMakes
StuffAndyMakes / iBeaconSample.h
Created December 16, 2013 20:20
iOS 7 iBeacon partial example (header)
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface iBeaconSample : NSObject <CLLocationManagerDelegate>
@property (strong, nonatomic) CLBeaconRegion *beaconRegion;
@property (strong, nonatomic) CLLocationManager *locationManager;
- (void)initRegion;