Skip to content

Instantly share code, notes, and snippets.

View Wollw's full-sized avatar

David E. Shere Wollw

View GitHub Profile
@Wollw
Wollw / adc_example.c
Created April 16, 2012 06:00
ATmega328P ADC conversion example
/* A simple ADC example that checks the analog reading on ADC0 and turns
* an LED on if the reading is higher than a threshold value and turns if
* off if it is under that value. */
#include <avr/io.h>
#include <stdint.h>
/* Which analog pin we want to read from. The pins are labeled "ADC0"
* "ADC1" etc on the pinout in the data sheet. In this case ADC_PIN
* being 0 means we want to use ADC0. On the ATmega328P this is also
* the same as pin PC0 */
@Wollw
Wollw / interrupt_example.c
Created April 14, 2012 00:17
AVR Timer Interrupt Examples
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdbool.h>
/*
* A global flag used to communicate between the Interrupt Service Routine
* and the main program. It has to be declared volatile or the compiler
* might optimize it out.
*/
volatile bool update = false;
@Wollw
Wollw / factorial-seq.dasm
Created April 6, 2012 20:38
DCPU-16 Examples
; Calculate each factorial from 1! -> N! where N the initial value
; of register B. When finished it pops each result into register J.
SET B, 5
SET C, 0
:LOOP
ADD C, 1
SET A, C
JSR FACTORIAL
@Wollw
Wollw / deque.c
Created April 6, 2012 08:53
Deque in C
#include <stdlib.h>
#include <assert.h>
#include "deque.h"
struct node_struct {
struct node_struct *next;
struct node_struct *prev;
deque_val_type val;
};
@Wollw
Wollw / class.c
Created April 3, 2012 02:59
Object Encapsulation in ANSI C
#include <malloc.h>
#include "class.h"
/* This is the actual implementation of the class.
* Because this file isn't included by main.c
* code in main.c can not access foo except through
* the functions declared in class.h.
*/
struct my_class_s {
int foo;
#include <avr/pgmspace.h>
#include "progmem.h"
int main() {}
@Wollw
Wollw / fizzbuzz.hs
Created March 25, 2012 22:52
FizzBuzz list comprehension
main=mapM_ putStrLn[case(if x`mod`3==0then"Fizz"else"")++(if x`mod`5==0then"Buzz"else"")of""->show x;s->s|x<-[1..100]]
@Wollw
Wollw / x11.go
Created March 19, 2012 18:20
Simple X11 Window in Go
package main;
import (
"exp/gui"
"exp/gui/x11"
"image"
)
func main() {
w,_ := x11.NewWindow()
/*
* This is a parser intended for Common Log Format access logs.
* It splits on whitespace unless it is part of a field delimited by
* square brackets or double quotes.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "parser.h"