Skip to content

Instantly share code, notes, and snippets.

View wrh2's full-sized avatar

William Harrington wrh2

View GitHub Profile
@wrh2
wrh2 / ema_filt.c
Created November 4, 2021 03:19
ema filter in C
#include <stdint.h>
#define BUF_SIZE 10 // usually how ever many ADC channels you want to filter
#define DATA_TYPE uint16_t
typedef struct{
unsigned int alpha; // filter constant
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
import matplotlib.pylab as plt
# Graphing helper function
def setup_graph(title='',x_label='', y_label='', fig_size=None):
fig = plt.figure()
if fig_size != None:
fig.set_size_inches(fig_size[0],
fig_size[1])
ax = fig.add_subplot(111)
ax.set_title(title)
/******************************************************************************
Proof of concept code for using function pointers to handle
byte encoded commands for an embedded system.
This is useful for using something such as CAN to communicate with an embedded system
Programmed by William Harrington
https://github.com/wrh2
*******************************************************************************/
@wrh2
wrh2 / has_ms_elapsed.py
Created October 3, 2018 04:52
check if x amount of milliseconds have elapsed (for windows)
import time
# good for about 1ms timing
def has_ms_elapsed(start_timestamp, num_of_ms):
return (time.clock() - start_timestamp)*1e3 > num_of_ms
# example use
def main():
# we'll wait 75ms in this example
@wrh2
wrh2 / bit-array2.c
Created August 24, 2018 18:55
Working with 2D arrays and bit manipulation in C. This example is especially helpful for working with images in C. Inspired by this stackoverflow question and answer: https://stackoverflow.com/questions/2525310/how-to-define-and-work-with-an-array-of-bits-in-c
/*
* Working with 2D arrays and bit manipulation in C
*
* Helpful for working with image processing in C
*
* For instance, let's say you have a 2D array in memory that
* represents a monochrome bitmap and you need to manipulate
* specific bits within that 2D array
*
* Programmed by William Harrington
@wrh2
wrh2 / binary.py
Created August 22, 2018 21:35
I use these for examining binary and hex in python because I hate how they trim leading 0's
def binary(num, length=32):
return format(num, '#0{}b'.format(length+2))
def hexadecimal(num, length=8):
return format(num, '#0{}x'.format(length+2))
#include <stdio.h>
/* states */
typedef enum{
IDLE,
BEGIN,
WAIT,
FINISH,
END,
}state_name_t;
/*
*Finite State Machine (FSM) Example in C
* that makes use of function pointers
*
* Programmed by wrh2 (github.com/wrh2)
*/
#include <stdio.h>
/* declare struct for FSM */
struct fsm;