Seven Segment LED’s are a common method of displaying data. With 8 datapins, they are also complicated to wire up, as each LED needs a Arduino pin and a resistor. With a library, we can simplify the wiring, and the data display. Typical displays look like the following:
Become the Maker you were born to be. Try Arduino Academy for FREE!
#include "SevSeg.h"
SevSeg sevseg; //Instantiate a seven segment controller object
void setup() {
Serial.begin(9600);
byte numDigits = 2; // number of modules
byte digitPins[] = {10,11}; // where your common pins are connected
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; //where your segments pins are connected
sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins); //Use COMMON_CATHODE if your modules use gnd on the common, or COMMON_ANODE if they take positive on the common.
sevseg.setBrightness(90);
}
void loop() {
int d1 = 12; // number you want displayed, usually from a sensor
sevseg.setNumber(d1, 1); //display number, with optional decimal point (1 place)
sevseg.refreshDisplay(); // Must run repeatedly
}
/// END ///
Become the Maker you were born to be. Try Arduino Academy for FREE!
More info at http://playground.arduino.cc/Main/SevenSegmentLibrary