Device:
Common anode 5461BS
Datasheet:
About:
I have search the web for a simple tutorial of how to connect and use a 7 Segment 4 Digit display,
I had a small idea to create a digital temperature monitor with the LM35 temperature sensor, but before that i had to understand how to work with the 7 segment 4 digit display.
I have connected the 5461BS device to the Arduino board as describe below -
my device is a common anode device, and since, i had to connect a resistor between each LED to the Arduino digital pin in order to lower the voltage and not to damage the LED light, i choose a 330ohm resistor, because this is what i had at the moment. An higher resistor number, means a dimmed LED.
The Code:
I found a very good and sufficient library from the following link -http://playground.arduino.cc/Main/SevenSeg
All i had to do is to read the "How To" manual and very quickly understand how to control the 7 segment 4 digit device.
the below example code will count from 0 to 2014 and will stay on 2014 on the 7 Seg device -
// Include 7 Segment 4 Digit library #include <SevenSeg.h> // Define the connection between the segment to the arduino, // Example - Arduino Pin 2 equiles LED a on the display SevenSeg disp(2, 3, 4, 5, 6, 7, 8); // Set number of digit to display const int numOfDigits = 4; // Define which Arduino Digital Pins will control the Digits int digitPins [numOfDigits] = { 10, 11, 12, 13}; // Declare x variable to the IF statment below int x = 0; void setup() { // Define SevenSeg to use 4 digits and where they are located disp.setDigitPins(numOfDigits, digitPins); Serial.begin(9600); disp.setDPPin(9); // Setup the Decimal Point disp.setRefreshRate(50); // Lower number means flickring LED } void loop(){ // A very basic code that will count to 2014 and then stop if (x == 0) { for(x = 0; x <= 2014; x++){ disp.write(x); Serial.println(x); } } else { disp.write(2014); } }
No comments:
Post a Comment