/* (c) 2022 Christian Grieger GNU GENERAL PUBLIC LICENSE Test the 7-segment display */ // Define shift register pins used for seven segment display #define LATCH_DIO 4 #define CLK_DIO 7 #define DATA_DIO 8 // Segment byte maps for numbers 0 to 9 const byte SEGMENT_MAP[] = { 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0X80, 0X90 }; // Byte maps to select digit 1 to 4 const byte SEGMENT_SELECT[] = { 0xF1, 0xF2, 0xF4, 0xF8 }; void setup () { pinMode(LATCH_DIO, OUTPUT); pinMode(CLK_DIO, OUTPUT); pinMode(DATA_DIO, OUTPUT); } void loop() { static int potiValue = 0; potiValue = analogRead(A0); /* Update the display with the current counter value */ toSegment(0, potiValue / 1000); toSegment(1, (potiValue / 100) % 10); toSegment(2, (potiValue / 10) % 10); toSegment(3, potiValue % 10); } void toSegment(byte segment, byte numValue) { digitalWrite(LATCH_DIO, LOW); shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[numValue]); shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[segment]); digitalWrite(LATCH_DIO, HIGH); }