SN74HC151N 8-Line to 1-Line Data Selectors/Multiplexers

used products:

1. 8 Position On/Off DIP Switch
2. Arduino UNO
3. LCD LiquidCrystal LCM1602C
4. SN74HC151N

Arduino:

#include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #define aPin 7 #define bPin 8 #define cPin 9 #define yPin 10 #define sleep 500 byte switchVar = 0; int matrix[][3] = { {0,0,0}, {0,0,1}, {0,1,0}, {0,1,1}, {1,0,0}, {1,0,1}, {1,1,0}, {1,1,1} }; void setup() { lcd.begin(16, 2); Serial.begin(9600); pinMode(aPin, OUTPUT); pinMode(bPin, OUTPUT); pinMode(cPin, OUTPUT); pinMode(yPin, INPUT); } void loop() { byte dataIn = 0; for (int i = 0; i < 8; i++) { digitalWrite(aPin, matrix[i][2]); digitalWrite(bPin, matrix[i][1]); digitalWrite(cPin, matrix[i][0]); int temp = digitalRead(yPin); if (temp) { dataIn = dataIn | (1 << i); } } if (switchVar != dataIn) { switchVar = dataIn; Serial.print("dataIn: "); Serial.print(dataIn, BIN); Serial.println(); delay(sleep); lcd.clear(); lcd.setCursor(0, 0); lcd.print("DEC: "+String(dataIn)); lcd.setCursor(0, 1); lcd.print("BIN: "+String(dataIn, BIN)); } }