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.

Here is the code for it

/* Arduino and sparkfun 7 segment display.

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

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


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


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(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--) {


No comments: