2. November 2010
// Example to hook up a 74AC138 Decoder // by defining the state of three outputs // one can switch off 1 out of 8 outputs of the Decoder // in this example NO Port manuipulation was used // for the ease of understanding... // constants ----------------------------- #define DATA1 8 #define DATA2 9 #define DATA3 10 // the setup ----------------------------- void setup() { //define pins 8,9,10 as outputs pinMode(DATA1, OUTPUT); pinMode(DATA2, OUTPUT); pinMode(DATA3, OUTPUT); } // the loop ----------------------------- void loop() { for (byte x = 0; x<=8; x++){ // function see below setPins(x); delay(80); } } // function definition -------------------- // the bits of the variable "number" are // sent out to the decoder void setPins(int number){ boolean d1 = bitRead(number, 0); boolean d2 = bitRead(number, 1); boolean d3 = bitRead(number, 2); digitalWrite(DATA1, d1); digitalWrite(DATA2, d2); digitalWrite(DATA3, d3); } [/sourcecode]