Advertisement
stenogriz

DIYTJ Module and Arduino

Sep 9th, 2013
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.62 KB | None | 0 0
  1. /*
  2.  
  3. Sergei A. Minayev, 2013
  4. DIYTJ LED Matrix Module test app
  5. Working app: http://youtu.be/R10uR81O0YM
  6.  
  7. */
  8.  
  9. const int aPin = 2;
  10. const int bPin = 3;
  11. const int cPin = 4;
  12. const int dPin = 5;
  13. const int oePin = 9;
  14. const int redPin = 8;
  15. const int greenPin = 7;
  16. const int strPin = 11;
  17. const int sckPin = 12;
  18.  
  19. int row = 0;
  20. int count = 0;
  21. int number, i = 0;
  22. int dig1, dig2, dig3, dig4 = 0;
  23.  
  24. // brutal font, zero element is 0; first element is 1 and so on...
  25. byte numbers[][16] = {
  26.     {B00000000, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000000}, // 0
  27.     {B00000000, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00000000}, // 1
  28.     {B00000000, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B01100000, B01100000, B01100000, B01100000, B01111110, B01111110, B00000000}, // 2
  29.     {B00000000, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B00000000}, // 3
  30.     {B00000000, B01100110, B01100110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000000}, // 4
  31.     {B00000000, B01111110, B01111110, B01100000, B01100000, B01100000, B01100000, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B00000000}, // 5
  32.     {B00000000, B01111110, B01111110, B01100000, B01100000, B01100000, B01100000, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000000}, // 6
  33.     {B00000000, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000110, B00000000}, // 7
  34.     {B00000000, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000000}, // 8
  35.     {B00000000, B01111110, B01111110, B01100110, B01100110, B01100110, B01100110, B01111110, B01111110, B00000110, B00000110, B00000110, B00000110, B01111110, B01111110, B00000000}, // 9
  36.   };
  37.  
  38. void setup() {
  39.   //set pins to output because they are addressed in the main loop
  40.   pinMode(aPin, OUTPUT);
  41.   pinMode(bPin, OUTPUT);  
  42.   pinMode(cPin, OUTPUT);
  43.   pinMode(dPin, OUTPUT);
  44.   pinMode(oePin, OUTPUT);
  45.   pinMode(redPin, OUTPUT);
  46.   pinMode(greenPin, OUTPUT);
  47.   pinMode(strPin, OUTPUT);
  48.   pinMode(sckPin, OUTPUT);
  49.   digitalWrite(oePin, LOW);
  50. }
  51.  
  52. void loop() {
  53.  
  54.   // DIYJT panel code --- start ---
  55.   digitalWrite(oePin, HIGH);
  56.   PORTD = (row << 2) & B00111100;
  57.   digitalWrite(greenPin, HIGH);
  58.   digitalWrite(strPin, LOW);
  59.   shiftOut(redPin, sckPin, MSBFIRST, ~(numbers[dig1][row]));
  60.   shiftOut(redPin, sckPin, MSBFIRST, ~(numbers[dig2][row]));
  61.   shiftOut(redPin, sckPin, MSBFIRST, ~(numbers[dig3][row]));
  62.   shiftOut(redPin, sckPin, MSBFIRST, ~(numbers[dig4][row]));
  63.  
  64.   digitalWrite(strPin, HIGH);
  65.   digitalWrite(oePin, LOW);
  66.  
  67.   if (row <= 14) row++; else row = 0;
  68.  
  69.   // DIYJT panel code --- end ---
  70.  
  71.   // counter code --- start ---
  72.  
  73.   if (count<=999) count++; else {
  74.     count = 0;
  75.     if (number<=9999) number++; else number = 0;
  76.     i = number;
  77.     dig1 = i/1000;
  78.     i = i-(dig1*1000);
  79.     dig2 = i/100;
  80.     i = i-(dig2*100);
  81.     dig3 = i/10;
  82.     i = i-(dig3*10);
  83.     dig4 = i;
  84.   }
  85.  
  86.   // counter code --- end ---
  87.  
  88.  
  89.   delayMicroseconds(500);
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement