Thread started: Nov 18 2007, 3:44 PM EST
Watch
arduino:
/* ReadMultiplexedSensorsAndSendMIDI
* ------------
*
* Reads 4 16 channel Multiplexers and sends the values
*
* Created 12 December 2005
* copyleft 2005 Stephen Williams <http://fluidforms.at> <http://algodes.com>
*
*/
#define CONTROLpin1 2
#define CONTROLpin2 3
#define CONTROLpin3 4
#define CONTROLpin4 5
// Variables:
char sensorValueToSend = 0; // Value of the sensor
int actualSensorValue = 0; // value from the analog input
// Some error chacking would be good here.
//If the values exceede 128 the will not fit in one byte.
void sendCommand(char command, char sensorID, char value) {
serialWrite(command);
serialWrite(sensorID);
serialWrite(value);
}
void setup() {
// set the states of the I/O pins:
pinMode(LEDpin, OUTPUT);
pinMode(CONTROLpin1, OUTPUT);
pinMode(CONTROLpin2, OUTPUT);
pinMode(CONTROLpin3, OUTPUT);
pinMode(CONTROLpin4, OUTPUT);
beginSerial(19200);
}
void loop() {
int i;
int j;
for (i=0; i <16; i++) {
// set control pins on the multiplexers
digitalWrite(CONTROLpin1, (i&15)>>3);//bit4
digitalWrite(CONTROLpin2, (i&7)>>2);//bit3
digitalWrite(CONTROLpin3, (i&3)>>1);//bit2
digitalWrite(CONTROLpin4, (i&1) );//bit1
// read the analogue inputs and send the values of the sensors.
for(j=0; j<4; j++){
actualSensorValue = analogRead(j);
// You will have to adjust this line so that can send the
// sensor value in one byte.
sensorValueToSend = actualSensorValue / 15;
sendCommand(0x90, i+16*j, sensorValueToSend);
}
// if you uncomment this line you can check the control pins
// of the multiplexers with your multimeter.
//delay(500);
}
}
out of
found this valuable.
Do you find this valuable?