/* * Use the `SevSeg` library to display an increasing number on * our four-digit-display. */ #include "SevSeg.h" SevSeg sevseg; //Instantiate a seven segment controller object void setup() { byte numDigits = 4; // // In the table above see how these refer to digits. // byte digitPins[] = {6,3,2,12}; // // In the table above see how these refer to the segments, // in alphabetical order :) // byte segmentPins[] = {5,13,10,8,7,4,11,9}; bool resistorsOnSegments = false; byte hardwareConfig = COMMON_CATHODE; sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments); sevseg.setBrightness(30); } // // The number we're displaying // int num=0; void loop() { // // How many times has this display-loop been called? // static int loop = 0; // // Bump our loop-index, increase if called enough // loop++; if ( loop > 1000 ) { num++; loop = 0; } // Handle over-flow if ( num > 9999 ) num = 0; // // Set the number. // sevseg.setNumber(num,0); // // Refresh the display // // NOTE: This only updates "some" segments each time it // is called, so you have to call it a lot - otherwise you // see gibberish. // // This is why we have the loop index. // sevseg.refreshDisplay(); }