// STRIBE SHIELD DEMO CODE - www.CuriousInventor.com/kits/stribe // Read 13 analog inputs and send their values over the serial port // Creative Commons 2.5 // 6/3/09 v0 // CuriousInventor.com // support: www.soundwidgets.com // Use, modify, share! // No Warranties whatsoever! // Change Log: // 6/3/09 // first release // HOW IT WORKS: // The CD4051 is a switch that lets you connect one pin to one of 8 other pins. This way you can read 8 lines with only one // pin on the arduino, giving a total 13 analog inputs when using the stribe_shield. // Three 4051 pins control which of the 8 pins connect to the common I/O pin. // Set your Serial Monitor to 57600 baud and connect analog signals to A0 - A4, and holes 0-7 along side the 4051 chip. // Don't attach anything to digital pins 4, 7 or 8--they're used to control the 4051. Also the 5th analog pin connects to the 4051. #define MULTIPLEX_A 8 // control lines for 4051 analog multiplexer #define MULTIPLEX_B 7 // #define MULTIPLEX_C 4 // int num_analog_inputs = 13; void setup() { pinMode(MULTIPLEX_A, OUTPUT); pinMode(MULTIPLEX_B, OUTPUT); pinMode(MULTIPLEX_C, OUTPUT); Serial.begin(57600); } void loop() { int j; for (j=0;j=5) { // use the 5th analog in channel to read up to 8 more channels, giving a total of 13 possible inputs ( 0 thru 4 + 8) if (j==5) { digitalWrite(MULTIPLEX_A, LOW); // connect A05 to 4051 mu channeltiplexerl 0 digitalWrite(MULTIPLEX_B, LOW); digitalWrite(MULTIPLEX_C, LOW); Serial.println(analogRead(5)); } else if (j==6) { digitalWrite(MULTIPLEX_A, HIGH); // channel 1 digitalWrite(MULTIPLEX_B, LOW); digitalWrite(MULTIPLEX_C, LOW); Serial.println(analogRead(5)); } else if (j==7) { digitalWrite(MULTIPLEX_A, LOW); // channel 2 digitalWrite(MULTIPLEX_B, HIGH); digitalWrite(MULTIPLEX_C, LOW); Serial.println(analogRead(5)); } else if (j==8) { digitalWrite(MULTIPLEX_A, HIGH); // channel 3 digitalWrite(MULTIPLEX_B, HIGH); digitalWrite(MULTIPLEX_C, LOW); Serial.println(analogRead(5)); } else if (j==9) { digitalWrite(MULTIPLEX_A, LOW); // channel 4 digitalWrite(MULTIPLEX_B, LOW); digitalWrite(MULTIPLEX_C, HIGH); Serial.println(analogRead(5)); } else if (j==10) { digitalWrite(MULTIPLEX_A, HIGH); // channel 5 digitalWrite(MULTIPLEX_B, LOW); digitalWrite(MULTIPLEX_C, HIGH); Serial.println(analogRead(5)); } else if (j==11) { digitalWrite(MULTIPLEX_A, LOW); // channel 6 digitalWrite(MULTIPLEX_B, HIGH); digitalWrite(MULTIPLEX_C, HIGH); Serial.println(analogRead(5)); } else if (j==12) { digitalWrite(MULTIPLEX_A, HIGH); // channel 7 digitalWrite(MULTIPLEX_B, HIGH); digitalWrite(MULTIPLEX_C, HIGH); Serial.println(analogRead(5)); Serial.println(); Serial.println(); Serial.println(); delay(1000); } } else { // read from the normal A0 thru A4 analog ports Serial.println(analogRead(j)); } } }