/*
7-Segment Display Test
This Arduino sketch demonstrates the use of a 74HC595 shift register to control a 7-segment display.
The display blinks the decimal point four times and then cycles through hexadecimal digits from 0 to F.
Pin Definitions:
- latchPin: Pin connected to the 74HC595 RCLK pin.
- clockPin: Pin connected to the 74HC595 CLK pin.
- dataPin: Pin connected to the 74HC595 DS pin.
- delayTime: Delay time in milliseconds for the main loop.
- blinkRate: Blink rate in milliseconds for the decimal point.
Segment Patterns:
- The segmentPatterns array holds binary patterns for displaying hexadecimal digits 0 to F and blinking the decimal point.
Author: [Nordl3]
Date: [12.3.24]
*/
// Pin Definitions
#define latchPin 10 // 74HC595 RCLK pin
#define clockPin 12 // 74HC595 CLK pin
#define dataPin 11 // 74HC595 DS pin
#define datapin1 9
#define delayTime 500 // Delay time in milliseconds
#define blinkRate 200 // Decimal Point blinkRate in milliseconds
// Segment patterns for digits 0 to F and decimal point blinking
const byte segmentPatterns[] =
{
B11111100, // 0 (0)
B01100000, // 1 (1)
B11011010, // 2 (2)
B11110010, // 3 (3)
B01100110, // 4 (4)
B10110110, // 5 (5)
B10111110, // 6 (6)
B11100000, // 7 (7)
B11111110, // 8 (8)
B11110110, // 9 (9)
B11101110, // A (10)
B11111110, // B (11)
B10011100, // C (12)
B01111010, // D (13)
B10011110, // E (14)
B10001110, // F (15)
B00000001, // . (16) (Decimal point)
B00000000
};
void setup()
{
// Initialize pins
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(datapin1, OUTPUT);
}
void loop()
{
//blinkLED();
//hexCounter();
displayDigit(7);
displayDigit(0);
delay(2000);
displayDigit(10);
//displayDigit(1);
displayShowCharacter(B11000000);
delay(2000); // Wait for X second
}
// Function to blink the decimal point four times
void blinkLED()
{
for (int j = 0; j < 4; j++)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, segmentPatterns[16]); // Display decimal point
digitalWrite(latchPin, HIGH);
}
}
// Function to display hexadecimal characters from 0 to F
void hexCounter()
{
for (int i = 0; i < 16; i++)
{
//displayDigit(8); // Display current digit
//displayDigit(16); // Display current digit
}
}
// Function to display a digit on the 7-segment display
void displayDigit(int digit1)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, segmentPatterns[digit1]); // Shift out the segment pattern for the digit
digitalWrite(latchPin, HIGH);
//delay(delayTime); // Wait for X second
//clearDisplay(); // Clear display
//delay(blinkRate); // Wait for X seconds
}
// Function to clear the display (turn off all segments)
void clearDisplay()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, B00000000); // Invert all bits to turn off segments
digitalWrite(latchPin, HIGH);
}
void displayShowCharacter(int character){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, character);
digitalWrite(latchPin, HIGH);
}