Advertisement
andrewb

_7seg_test2.cpp

Oct 21st, 2014
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. /**********************************************************************
  2.  * A test driver for using the Radio Shack 7-segment component 276-0075
  3.  * with an Aruino Uno R3 and a Sparkfun 74HC595 IC.
  4.  **********************************************************************/
  5.  
  6. // Setup the SIPO pins
  7. int dataPin = 13;    //Pin connected to DS of 74HC595
  8. int latchPin = 12;   //Pin connected to ST_CP of 74HC595
  9. int clockPin = 11;   //Pin connected to SH_CP of 74HC595
  10.  
  11. // Counter
  12. int counter = 0;
  13. // The binary numbers to activate the 74HC595 pins. 0-F
  14. int pins[] = {B10111101, B10100000, B00111110, B10111010,
  15.               B10100011, B10011011, B10011111, B10110000,
  16.               B10111111, B10111011, B10110111, B10001111,
  17.               B00011101, B10101110, B00011111, B00010111};
  18. // The length of the pins array.
  19. const int MAX = sizeof(pins)/sizeof(int);
  20.  
  21. // Start
  22. void setup() {
  23.   //set pins to output so you can control the shift register
  24.   pinMode(latchPin, OUTPUT);
  25.   pinMode(clockPin, OUTPUT);
  26.   pinMode(dataPin, OUTPUT);
  27. }
  28.  
  29. // Main loop
  30. void loop() {
  31.   changePattern(pins[counter]);
  32.   counter++;
  33.   if (counter == MAX) counter = 0;
  34.   delay(500);  
  35. }
  36.  
  37. // Sets the write to low, changes the number, and sets write to high to
  38. // light up the display.
  39. void changePattern(int n) {
  40.     digitalWrite(latchPin, LOW);
  41.     shiftOut(dataPin, clockPin, MSBFIRST, n);
  42.     digitalWrite(latchPin, HIGH);  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement