7 Segment Display
7 Segment Display Sparkfun 09767
Das Display bei Sparkfun.
Für die Ansteuerung braucht es nur +5V, GND sowie eine Verbindung mit dem Rx Pin.
Für die Serielle Verbindung wird hier die NewSoftSerial Bibliothek verwerndet.
/*
Example for Sparkfun 4 Digit 7 Segment Display 09767
Pin Configuration:
VCC - 2,6 - 5,5V
GND - GND
RX - Serial Pin Arduino
This code uses New Soft Serial Library
All pins are possible serial pins...
DOWNLOAD http://arduiniana.org/libraries/newsoftserial/
*/
#include
NewSoftSerial mySerial(4, 5); // define Rx Tx Pins
byte count = 0; // conter
byte decimals[4]; // decimals array
// the setup -------------------------------------------------
void setup()
{
Serial.begin(9600); // setup serial communication
Serial.println("start"); // between arduino and computer
mySerial.begin(9600); // setup software serial communication
delay(100); // between arduino and 7 segment display
mySerial.print(0x76); // reset the 7 segment display
}
// the loop -------------------------------------------------
void loop()
{
calculateDigits(count, decimals); // pass the count and decimals array as argument
// to calculate the single digits form a 3 decimals number
// from 0 - 255
// 234 becomes 2, 3, 4
showDigits(decimals); // pass the decimals array as argument
// and write them to the screen
count++;
if (count > 255){
count = 0;
}
delay(500);
}
// functions -------------------------------------------------
void showDigits(byte pdata[]){
mySerial.print(pdata[0]);
mySerial.print(pdata[1]);
mySerial.print(pdata[2]);
mySerial.print(pdata[3]);
}
void calculateDigits(byte cnt, byte pdata[]){
pdata[0] = 0x78; // empty character
pdata[1] = cnt /100; // 100
pdata[2] = (cnt /10) % 10; // divided by 10 modulo 10
pdata[3] = (cnt % 100) % 10; // modulo 100 modulo 10
}