Forums Coding Corner A little digital display fun

Viewing 1 reply thread
  • Author
    • #6860

      I was curious about how the digital segments were mapped so I wrote a little sketch to figure it out. Since I’m new to the language, I started with the digital clock, stripped out what I wouldn’t need and started from there. Hope you enjoy.

      // Quick sketch to show use of digital segments.

      //RTC Stuff
      #include “RTClib.h” // Include RTClib library
      RTC_DS1307 rtc; // Create an instance of the DS1307

      //DIGITISER Stuff

      const int OE = 10;
      const int SER = 3;
      const int CLK = 4;
      const int LATCH = 5;

      const int sw1 = A0;
      const int sw2 = A2;
      const int Pot = A1;

      int potRead = 0;
      int potDimVal = 0;

      int num = 0;

      const int digit[4] =

      int digit0 = digit[0];
      int digit1 = digit[1];
      int digit2 = digit[2];
      int digit3 = digit[3];

      // Segment comments
      // The segments in each Digit display are addressed using a simple
      // switch matrix. Using 1 byte – each bit represents or addresses a single
      // segment of the display. A one is off and a zero is on.
      // Likewise each digit is selected using the switch matrix above these comments
      // with using binary one through 4.

      // The list below shows which bit turns on which segment.
      // Below the list is the content of the seg constant which places them in
      // the order of All off then rotating starting with the dot, lower left, upper left
      // etc. ending with the center segment then all on.

      const int seg[10]=

      // B01111111 is Center Segment
      // B10111111 is Upper Left Segment
      // B11011111 is Top Segment
      // B11101111 is Upper Right Segment
      // B11110111 is Dot in Lower Right
      // B11111011 is Lower Right Segment
      // B11111101 is Bottom Segment
      // B11111110 is Lower Left Segment
      // B11111111 is All Segments Off
      // B00000000 is All Segments On


      int seg0 = seg[4];

      void setup() {

      // Start Serial Comminication


      //RTC Stuff


      // Uncomment next line to set clock – then re-comment it out to prevent every time set

      rtc.adjust(DateTime(__DATE__,__TIME__));; // Set the RTC to Compile Date and Time

      //DIGITISER Stuff

      pinMode(SER, OUTPUT); // SER (data) pin as output
      pinMode(CLK, OUTPUT); // CLK (clock) pin as output
      pinMode(LATCH, OUTPUT); // LATCH pin as output
      pinMode(OE, OUTPUT); // Output Enable

      analogWrite(OE, 150); // Set brightness

      pinMode(sw1, INPUT); // Switch 1
      pinMode(sw2, INPUT); // Switch 2
      pinMode(Pot, INPUT); // Potentiometer


      void loop() {

      //DIM DISPLAY USING POTENTIOMETER after each sequence of Digits

      potRead = analogRead(Pot); // Reads the pot and assigns potRead the same value
      potDimVal = map(potRead,0,1023,255,0); // maps potRead (0-1023) to potDimVal (255-0)
      analogWrite(OE,potDimVal); // Sets a PWM value (potDimVal) to the OE pin to set brightness

      int nm = 0;
      nm = 0;

      while (nm < 10)

      // delay quarter second between segments
      int d1 = 250;

      // Push which segment to light
      digitalWrite(LATCH, LOW);




    • #6865

      It’s nice to see I am not the only one. This is the way we learn I guess. Well done.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.