Wednesday 8 March 2017

Arduino - 7 Segment LED

Arduino Project #3


9 Second Seven Segment LTD Countdown Buzzer



This is a 7 segment LED connected to a 595N shift register.  When it counts down from 9 to 0 second, the buzzer will be activated.



Arduino circuit and sketch

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 9;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 10;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 8;
const int buzz = 7;
const byte CHAR_COUNT = 10;

const byte symbols[CHAR_COUNT] = {
B01111110, // 0
B00010010, // 1
B10111100, // 2 
B10110110, // 3
B11010010, // 4 
B11100110, // 5
B11101110, // 6 
B00110010, // 7
B11111110, // 8 
B11110110  // 9
};

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  pinMode(buzz, OUTPUT);
  
}

void loop() {
  pattern1();

}

void pattern1()
{
  int i=9;
  while(i<CHAR_COUNT)
  {
    writeLeds(symbols[i]);
    if (i==0)
    tone(buzz,1000,1000);
    else 
    i = i-1; 
    delay(1000);
     
  }
}
void writeLeds(byte pattern)
{
  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);
  // turn on the next highest bit in bitsToSend:
  Serial.println(pattern,BIN);

  // shift the bits out:
  shiftOut(dataPin, clockPin, MSBFIRST, pattern);

    // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);
  }

Component Required:
seven segment LED, 595N Shift register, Buzzer, 220 Ohm resistor

Problem you may encounter:
If your 7 segment LED randomly lights up instead of showing numbers, you may try to change all the '1' into '0' and all '0' into '1' when you define 'symbols[CHAR_COUNT]'.




 





No comments:

Post a Comment