The Arduino Playground has examples of that sort of thing.
http://arduino.cc/playground/Main/InterfacingWithHardware#Output