const byte rowPins[5] = {9, 10, 11, 12, 13};
const byte columnPins[4] = {2, 3, 4, 5};
const byte rows = 5, columns = 4;
const unsigned long digits[10] = {
0b11111001100110011111, // 0
0b01000110010001000100, // 1
0b01101001010000101111, // 2
0b01101001010010010110, // 3
0b10011001111110001000, // 4
0b11110001111110001111, // 5
0b11111000111110011111, // 6
0b11111000010000100001, // 7
0b11111001111110011111, // 8
0b11111001111110001111 // 9
};
int bitPosition, resistance = 1, previousResistance = 0;
bool bitValue;
byte whichDigit;
const byte digitZero[5][4] = {
{1, 1, 1, 1},
{1, 0, 0, 1},
{1, 0, 0, 1},
{1, 0, 0, 1},
{1, 1, 1, 1}
};
void setup() {
Serial.begin(9600);
for (int i = 0; i < rows; i++) {
pinMode(rowPins[i], OUTPUT);
digitalWrite(rowPins[i], LOW);
}
for (int i = 0; i < columns; i++) {
pinMode(columnPins[i], OUTPUT);
digitalWrite(columnPins[i], HIGH);
}
pinMode(8, INPUT);
}
void loop() {
resistance = map(analogRead(8), 0, 1023, 0, 9);
Serial.println(resistance);
for (int j = 0; j < rows; j++) {
digitalWrite(rowPins[j], HIGH);
for (int i = 0; i < columns; i++) {
bitPosition = j * columns + i;
bitValue = (digits[resistance] >> bitPosition) & 1;
digitalWrite(columnPins[i], bitValue ? LOW : HIGH);
}
for (int i = 0; i < columns; i++) {
digitalWrite(columnPins[i], HIGH);
}
digitalWrite(rowPins[j], LOW);
}
}
/*for (int i = 15; i >= 0; --i) {
// Extract the i-th bit
bool bit = (digitOne >> i) & 1;
// Compare the bit with something else (e.g., check if it's 1)
if (bit == 1) {
Serial.println("Bit "+String(i)+" is 1");
} else {
Serial.println("Bit "+String(i)+" is 0");
}
}*/