SHARE
TWEET

Untitled

a guest Dec 14th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. // PROJECT  :McKenna&DolginMatrix
  4. // PURPOSE  :Demo program of the MatrixMadeEZ Device (original design by H. Reed)
  5. // RESULT   :First four rows of the main diagonal should light up as bright as possible
  6. // AUTHOR   :C. D'Arcy
  7. // DATE     :2019 12 03
  8. // uC       :328P
  9. // STATUS   :Working
  10. // REFERENCE:https://cdn-shop.adafruit.com/datasheets/1079datasheet.pdf
  11. #define DMLEVEL 0           //since /G on TPIC:  bright:0, dim:250ish
  12. #define LIMIT 0xFF          //adjust for length of diagonal
  13. #include <TimerOne.h>
  14. uint8_t dimmer = 3;         //PWM (or external voltage divider, eg pot, LDR)
  15. uint8_t data = 7;          //avoid pins 9 and 10 for later use
  16. uint8_t latch = 5;         //of the TimerOne library to control
  17. uint8_t clk = 6; //frame speed
  18. uint8_t score1 = 0;
  19. uint8_t score2 = 0;
  20. uint8_t redInput1 = A5;
  21. uint8_t redInput2 = A4;
  22. uint8_t redInput3 = A3;
  23. uint8_t grnInput1 = A2;
  24. uint8_t grnInput2 = A1;
  25. uint8_t grnInput3 = A0;
  26. uint8_t reset = 2;
  27.  
  28. uint8_t scoreR1 = 0;
  29.  
  30. uint8_t board[8];
  31. uint8_t rowData[][3] = { {0b11111000, 0b10001000, 0b11111000}, {0b00000000, 0b000000000, 0b11111000}, {0b10111000, 0b10101000, 0b11101000},
  32.   {0b10101000, 0b10101000, 0b11111000}, {0b11100000, 0b00100000, 0b11111000}, {0b11101000, 0b10101000, 0b10111000}, {0b11111000, 0b10101000, 0b10111000}, {0b11000000, 0b10000000, 0b11111000}, {0b11111000, 0b10101000, 0b11111000}, {0b11100000, 0b10100000, 0b11111000},
  33.   {0b11111000, 0b10100000, 0b11111000},{0b11111000, 0b10101000, 0b01110000}, {0b11111000, 0b10001000, 0b10001000},{0b11111000, 0b10001000, 0b01110000},{0b11111000, 0b10101000, 0b10101000},{0b11111000, 0b10100000, 0b10100000},
  34. };   //let's light the main diagonal
  35. uint8_t colData = 0x80;  //equate the row and column coordinates
  36. //uint8_t colData2 = 0x04;
  37.  
  38. void setup() {
  39.   Serial.begin(9600);
  40.   pinMode(dimmer, OUTPUT);        //
  41.   pinMode(data, OUTPUT);          //
  42.   pinMode(clk, OUTPUT);           //
  43.   pinMode(latch, OUTPUT);         //
  44.   analogWrite(dimmer, DMLEVEL);   //brightness control on the /G pin of the TPIC
  45.   randomSeed(analogRead(A0));
  46.   Timer1.initialize(150000);
  47. }
  48.  
  49.  
  50.  
  51. void loop() {
  52.  
  53.  
  54.   uint8_t binNumber = 0;
  55.   Serial.println(binNumber, BIN);
  56.   for (uint8_t j = 0; j < 3; j++) {
  57.     board[j] = rowData[score1][j];
  58.     board[j + 5] = rowData[score2][j];
  59.   }
  60.  
  61.   //While input 1 or 2 are not equal to bin value keep doing POV
  62.  
  63.  
  64.   for (uint8_t i = 0; i < 8; i++) {
  65.     digitalWrite(latch, LOW);
  66.     shiftOut(data, clk, MSBFIRST, colData >> i); //note the shift order
  67.     shiftOut(data, clk, MSBFIRST, board[i] ); //and the column data first
  68.     digitalWrite(latch, HIGH);
  69.     digitalWrite(latch, LOW);
  70.     for (uint8_t i = 0; i < 3; i++) {
  71.       digitalWrite(latch, LOW);
  72.       shiftOut(data, clk, MSBFIRST, binNumber << 2); //and the column data first
  73.       shiftOut(data, clk, MSBFIRST, colData >> i + 5); //note the shift order
  74.     }
  75.     digitalWrite(latch, HIGH);
  76.  
  77.     /*if ( digitalRead(binInput1) == LOW) {
  78.        score1++;
  79.        delay(150);
  80.       }*/
  81.     if ( digitalRead(redInput1) == HIGH) {
  82.       if (score1 == 15) { } else {
  83.         score1++;
  84.         delay(150);
  85.       }
  86.     }
  87.     if ( digitalRead(grnInput1) == HIGH) {
  88.       if (score2 == 15) { } else {
  89.         score2++;
  90.         delay(150);
  91.       }
  92.     }
  93.     if ( digitalRead(redInput2) == HIGH) {
  94.       if (score1 == 15 || score1 == 14) { } else {
  95.         score1 += 2;
  96.         delay(150);
  97.       }
  98.     }
  99.     if ( digitalRead(grnInput2) == HIGH) {
  100.       if (score2 == 15 || score2 == 14) { } else {
  101.         score2 += 2;
  102.         delay(150);
  103.       }
  104.     }
  105.     if ( digitalRead(reset) == HIGH) {
  106.       score1 = 0;
  107.       score2 = 0;
  108.       delay(150);
  109.     }
  110.  
  111.  
  112.   }
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top