Saturday, September 25, 2010

Arduino and sparkfun 7 segment display

Here is a simple demo I made of an arduino and sparkfun 7 segment display.

http://www.youtube.com/watch?v=dLDefQAYy4s

Here is the code for it



/* Arduino and sparkfun 7 segment display. http://www.sparkfun.com/commerce/product_info.php?products_id=9765

Counts up to 5000 and back down to 0. Speed of counting is adjustable by a potentiometer.

My code is based off the code from this tutorial
http://www.arunet.co.uk/tkboyd/ec/ec1led4x7ser.htm

A big thanks to the person that wrote that tutorial.

You will need to install the newsoftserial library for this code to work.

Wiring is simple.

Digital pin 3 on arduino to RX on display.
Ground pin on arduino to GND on display.
5 volt pin on arduino to VCC on display

The pot is hooked up to analog input pin 0. If you don't know how to hook up a pot. Look for videos on youtube.
*/


#include //Make sure you have this library installed,

#define SerInToArdu 2 // input pin to arduino. Not used in this example
#define SerOutFrmArdu 3 // output pin from arduino




NewSoftSerial mySerialPort(SerInToArdu,SerOutFrmArdu); //creates a serial //channel to send the data to and from the display.


void setup(){

pinMode(SerOutFrmArdu,OUTPUT); //sets pin to output
pinMode(SerInToArdu,INPUT);//Not actually needed... put in to be explicit as to //data direction over serial lines

mySerialPort.begin(9600);

/* send a "v" to the display. It's a special code to reset the display. See tutorial above for more info on special codes */
mySerialPort.print("v");

}

void loop(){

for (int num = 0; num <= 5000; num++) { //simple for loop

/*reset display. Makes numbers show up better. Try it without the reset to see what it looks like*/
mySerialPort.print("v");
mySerialPort.print(num); //send value of num to display
delay(analogRead(0)); //delay by pot value
}

//same as above except for loop goes in pposite direction
for (int num = 5000; num >= 0; num--) {
mySerialPort.print("v");
mySerialPort.print(num);
delay(analogRead(0));
}

}

No comments: