Skip to content

Instantly share code, notes, and snippets.

Martin Boekhoff madex

  • Germany
View GitHub Profile
View rcube.scad
module rcube(v, r, center=false, $fn=40) translate(center ? [-v[0]/2,-v[1]/2,-v[2]/2] : [0,0,0]) hull() {
translate([r,r, r]) sphere(r=r); translate([r, r, v[2]-r]) sphere(r=r);
translate([v[0]-r, r, r]) sphere(r=r); translate([v[0]-r, r, v[2]-r]) sphere(r=r);
translate([r, v[1]-r,r]) sphere(r=r); translate([r, v[1]-r,v[2]-r]) sphere(r=r);
translate([v[0]-r, v[1]-r,r]) sphere(r=r); translate([v[0]-r, v[1]-r,v[2]-r]) sphere(r=r);
}
translate([0, 20, 0]) rcube([15,10,20], r=1, center=false);
translate([0, 0, 0]) cube([15,10,20], center=false);
@madex
madex / hex2nibbel.c
Created Nov 27, 2015
helper for hex parsing
View hex2nibbel.c
uint8_t hexCharToNibbel(char hexChar) {
return (hexChar >= '0' && hexChar <= '9') ? hexChar - '0' :
(hexChar >= 'A' && hexChar <= 'F') ? hexChar - 'A' + 10 : 16;
}
@madex
madex / softi2c.c
Last active Aug 29, 2015
universal software i2c for microcontrollers
View softi2c.c
// example for xmega256d3
// bit delay
static void delay(void) {
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
@madex
madex / div10.c
Created Oct 20, 2014
division by 10 as multply an shift.
View div10.c
// (uint64_t val) 26 till 11184819 correct, (uint32_t val) 19 bis 81920 correct
#define BITS 19
#define MUL (((1L << BITS)/10) + 1)
unsigned long div10(unsigned long val) {
return ((unsigned long) val * MUL) >> BITS;
}
@madex
madex / itoaUint32VarLen.c
Created Oct 20, 2014
unsigned 32bit output with lenghtInChars width, either filled with '0' or with ' ' depending on fillWith0. if value is bigger than the value that is possible within lenghtInChars, the maximum possible value is shown.
View itoaUint32VarLen.c
char *itoaUint32VarLen(uint32_t value, uint8_t fillWith0, uint8_t lenghtInChars) {
static uint8_t sBuf0[12]; // maximum Value -2147483649 = 12
uint8_t *sBuf = &sBuf0[11], *sBufWerteBegrenzung;
uint32_t valueAlt; // Alte Wert für schneller % 10 Berechnung
*sBuf = 0;
if (value == 0) {
*--sBuf = '0';
lenghtInChars--;
} else while (value) {
if (!lenghtInChars) {
@madex
madex / hexdump.c
Created Oct 20, 2014
hexdump that requires only a putchar() function, for microcontoller
View hexdump.c
void hexDump(char *description, void *basisAddr, void *startAddr, unsigned long len) {
unsigned char i = 0;
unsigned long tempAdr;
char hex[] = "0123456789abcdef";
unsigned char buff[17], *ptrBuf;
unsigned char *pc = (unsigned char*) startAddr;
if (description != NULL) {
while (*description)
putchar(*description++);
putchar('\n');
@madex
madex / atoi.c
Created Oct 20, 2014
small converter for string decimal numbers integers for microcontoller. Numbers can be negeative and starting spaces are ignored.
View atoi.c
int atoi(const char *c) {
int result = 0;
int sign = 1;
if (!c)
return 0;
while (*c == ' ')
c++;
if (*c == '-') {
sign = -1;
c++;
@madex
madex / itoaFixedWidth.c
Last active Aug 29, 2015
Fast 32bit signed itoa without division and with fixed width (base 10) filled up with spaces.
View itoaFixedWidth.c
char *itoaFixedWidth(int32_t zahl) {
static uint32_t subtractors[] = {1000000000, 100000000, 10000000, 1000000,
100000, 10000, 1000, 100, 10, 1};
static char string[12];
char n, *str = string, sign = zahl < 0 ? '-' : ' ';
uint32_t *sub = subtractors;
uint32_t u = zahl < 0 ? (uint32_t) -zahl : (uint32_t) zahl;
uint8_t i = 10;
*str++ = ' ';
while (i > 1 && u < *sub) {
@madex
madex / sudoku.c
Last active Aug 29, 2015
my obfuscated sudoku solver
View sudoku.c
#include <stdio.h>
#define _ 0
#define S(x) x,
#define D(x) x x x
#define L(x) D(S(x))
#define R(x) D(D(S(x)))
#define E(f,x) f(x)f(x+1)f(x+2)
char sudoku[] = {
1, _, _, _, _, 7, _, 9, _,
_, 3, _, _, 2, _, _, _, 8,
You can’t perform that action at this time.