We also got a code for a sing mux from Chris, and this code was wotking perfectly. Here is a code.
int val[16];
//variables in this code have been changed from their original value of Int to byte.
int a= 3; // SELECT PIN A0 GOING INTO PIN 2
int b= 4; // SELECT PIN A1 GOING INTO PIN 3
int c= 5; // SELECT PIN A2 GOING INTO PIN 4
int d= 6; // SELECT PIN A3 GOING INTO PIN 5
int analog0 = 0;
void setup() {
Serial.begin(9600);
pinMode(analog0, INPUT);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
}
void loop() {
for (int channelNum = 0; channelNum < style="font-style: italic; color: rgb(51, 102, 102);">
// determine the four address pin values from the channelNum:
// mask off bit 0:
int pinOne = 1 & channelNum;
// shift value 1 bit to the right, and mask all but bit 0:
int pinTwo = 1 & (channelNum >> 1) ;
// shift value 2 bits to the right, and mask all but bit 0:
int pinThree = 1 & (channelNum >> 2);
// shift value 3 bits to the right, and mask all but bit 0:
int pinFour = 1 & (channelNum >> 3);
// set the address pins:
digitalWrite(a,pinOne);
digitalWrite(b,pinTwo);
digitalWrite(c,pinThree);
digitalWrite(d,pinFour);
// read the analog input and store it in the value array:
val[channelNum] = analogRead(analog0);
// print the values as a single tab-separated line:
Serial.print(val[channelNum], DEC);
Serial.print("\t");
}
// print a carriage return at the end of each read of the mux:
Serial.println();
}
Tuesday, December 11, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment