// # Sample code "arduinocd4051b01.ino" V 1.00 Written by Henrik Bruun 1234@567.dk # # This sample code works on Ardruino pro mini with 4151 ic, and expand 1 analog port to 8 ports # // const int analogInPin = A0; // Analog input pin that the 4051 is attached to int sensorValue = 0; // value read from the pot int bit1 = 10; // S0 on 4051 pin9 int bit2 = 11; // S1 on 4051 pin10 int bit3 = 12; // S2 on 4051 pin11 int del = 2; int mySensVals[8] = {0,0,0,0,0,0,0,0}; int value = 0; // value from count long interval = 1000; // interval between read (milliseconds) void setup() { // initialize serial communications at 115200 bps: Serial.begin(115200); pinMode(bit1, OUTPUT); pinMode(bit2, OUTPUT); pinMode(bit3, OUTPUT); } void loop() { Serial.println(""); Serial.println(""); Serial.println("---------------------------"); Serial.println("Y0-Y1-Y2-Y2-Y3-Y4-Y5-Y6-Y7-"); Serial.println("- - - - - - - - - - - - - -"); // Prints header every "beforeheader" lines for (int beforeheader = 0; beforeheader < 20 ; beforeheader++) { for (int count = 0; count < 8 ; count++) { value = count % 8; digitalWrite(bit1, (value >> 0) % 2); // LSB digitalWrite(bit2, (value >> 1) % 2); digitalWrite(bit3, (value >> 2) % 2); // MSB // delay(5); // You can add an delay after mySensVals[count] = analogRead(analogInPin); // Store Sensor value in Array Serial.print(mySensVals[count]); // Print Sensor value from array Serial.print("-"); } delay(interval); Serial.println(""); // Print new line after read of the 8 interfaces } }