Skip to content

Instantly share code, notes, and snippets.

View JamesNewton's full-sized avatar
💭
Dexter rocks!

JamesNewton

💭
Dexter rocks!
View GitHub Profile
@JamesNewton
JamesNewton / macros.h
Created November 4, 2021 00:51
Good C / C++ macros
//the Arduino map function.
#define MAP(x, in_min, in_max, out_min, out_max) (((x) - (in_min)) * ((out_max) - (out_min)) / ((in_max) - (in_min)) + (out_min))
#define SIGN(i) ((i)>0? 1:(i)<0?-1:0)
#define MAX(a, b) ((a)>(b)?(a):(b))
#define MIN(a, b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)<0?(0-(a)):(a))
@JamesNewton
JamesNewton / encoderdisk.jscad
Last active October 15, 2019 15:51
OpenJSCAD code to make an encoder disk, Moved to: https://github.com/JamesNewton/HybridDiskEncoder
// title : OpenJSCAD.org encoder disk
// author : James Newton
// license : MIT License
// revision : 0
// tags : hdrobotics.com
// file : encoderdisk.jscad
// http://openjscad.com/#https://gist.githubusercontent.com/JamesNewton/c8598878736442c440bbe41d086291ac/raw//encoderdisk.jscad
function getParameterDefinitions() {
return [
@JamesNewton
JamesNewton / BinHexExamples.c
Created February 2, 2018 01:49
Options for shortest possible binary to hex, multiple data types, light, fast, easy for the C compiler to optimize.
//For a live version of this, see:
//https://ideone.com/HDqleJ
#include <stdio.h>
#define loctype long
//#define loctype short
//#define loctype double
//#define loctype float
#define value 3735928559 //a fun value which turns into DEADBEEF in hex.
#define EOL 13
@JamesNewton
JamesNewton / csv2OpenSCAD2png.bat
Created July 26, 2017 23:05
Render CSV data into png files for animation / video overlay via OpenSCAD
@echo off
if NOT [%2]==[] goto :doit
echo Usage:
echo %0 data.csv script.scad parameters
echo Where:
echo - data.csv is a csv file where each line corrisponds to a single frame to be produced in the PNG file
echo.
echo - script.scad is the script which will render the line of data into the PNG frame.
echo The script should parse the line of data and render a valid output
@JamesNewton
JamesNewton / PinReadWrite.ino
Last active August 30, 2023 01:10
Simple Arduino script to set pins high, low, input, pull up, or analog/servo, clock in or out data, with timing/start/stop, and read all or a single pin back via serial IO. NOTE: THIS HAS BEEN REPLACED BY https://github.com/JamesNewton/Arduino_Dynamixel_Stepper_Controller
/*
PinReadWrite.ino
//20170512 initial version
//20170517 uS timing (was mS), vars are longs, i2C start/stop, and clock IN data w/.
//20201002 Returns valid JSON.
Simple Arduino script to set pins high, low, input, pull up, or analog/servo,
clock out data with timing, and read all or a single pin back via serial IO.
Written for the tiny-circuits.com TinyDuino in the end effector of the
Dexter robot from HDRobotic.com, but generally useful to turn the Arduino
@JamesNewton
JamesNewton / MassMind.org ENC1 3Wire ReadAngle Arduino
Created May 8, 2017 19:13
Arduino code to read the angle register from the MassMind.org ENC1 via 3 wire read only mode.
/*
Source from
http://forum.arduino.cc/index.php?topic=78881.msg1375885#msg1375885
* Ahmad Byagowi ([email protected])
* Date : Aug 31, 2013
* All code (c)2013 Ahmad Byagowi Consultant. all rights reserved
20170508 Minor edits to improve clarity by James Newton.
*/
//c2 pin tied to ground for 3 wire mode