SN74HC148N 8-Line To 3-Line Priority Encoders

used products:

1. Arduino UNO
2. SN74HC148N

Arduino:

int pins[8] = {2,3,4,5,6,7,8,9}; byte matrix[8] = { B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111 }; void setup() { Serial.begin(9600); for (int i = 0; i < 8; i++) { pinMode(pins[i], OUTPUT); } } void loop() { byte mask; for (int j = 0; j < 8; j++) { byte data = matrix[j]; for (int i = 7; i >= 0; i--) { mask = 0x01 << i; int v = !!(data&mask); Serial.print(v); digitalWrite(pins[7-i], v); } Serial.println(); delay(500); } }