Guest User

Untitled

a guest
Jan 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <LedMatrix.h>
  3.  
  4. //LED Matrix Pins
  5. #define NUMBER_OF_DEVICES 4
  6. #define CS_PIN 15
  7. #define CLK_PIN 14
  8. #define MISO_PIN 2 //Not Used
  9. #define MOSI_PIN 12
  10.  
  11. LedMatrix ledMatrix = LedMatrix(NUMBER_OF_DEVICES, CLK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
  12.  
  13. void setup() {
  14. ledMatrix.init();
  15. ledMatrix.setText("Jam");
  16.  
  17. pinMode(4, INPUT_PULLDOWN);
  18. pinMode(5, INPUT_PULLDOWN);
  19. pinMode(16, INPUT_PULLDOWN);
  20. pinMode(17, INPUT_PULLDOWN);
  21. pinMode(18, INPUT_PULLDOWN);
  22. pinMode(19, INPUT_PULLDOWN);
  23. pinMode(21, INPUT_PULLDOWN);
  24. pinMode(23, INPUT_PULLDOWN);
  25.  
  26. analogReadResolution(10);
  27. pinMode(32, INPUT);
  28. pinMode(33, INPUT);
  29. pinMode(34, INPUT);
  30. pinMode(35, INPUT);
  31. pinMode(36, INPUT);
  32. }
  33.  
  34. void loop() {
  35. for (int i=0; i<28; i++)
  36. {
  37. ledMatrix.clear();
  38. ledMatrix.scrollTextLeft();
  39. ledMatrix.drawText();
  40. ledMatrix.commit();
  41. delay(100);
  42. }
  43. delay(1500);
  44.  
  45. while (1)
  46. {
  47. ledMatrix.clear();
  48. int pot1 = analogRead(32)/110;
  49. setcolbotval(5,pot1);
  50. setcolbotval(6,pot1);
  51. setcolbotval(7,pot1);
  52. int pot2 = analogRead(33)/110;
  53. setcolbotval(10,pot2);
  54. setcolbotval(11,pot2);
  55. setcolbotval(12,pot2);
  56. int pot3 = analogRead(34)/110;
  57. setcolbotval(15,pot3);
  58. setcolbotval(16,pot3);
  59. setcolbotval(17,pot3);
  60. int pot4 = analogRead(35)/110;
  61. setcolbotval(20,pot4);
  62. setcolbotval(21,pot4);
  63. setcolbotval(22,pot4);
  64. int pot5 = analogRead(36)/110;
  65. setcolbotval(25,pot5);
  66. setcolbotval(26,pot5);
  67. setcolbotval(27,pot5);
  68. char btns = 0;
  69. if (digitalRead(4) == HIGH) btns+=1;
  70. if (digitalRead(5) == HIGH) btns+=2;
  71. if (digitalRead(16) == HIGH) btns+=4;
  72. if (digitalRead(17) == HIGH) btns+=8;
  73. if (digitalRead(18) == HIGH) btns+=16;
  74. if (digitalRead(19) == HIGH) btns+=32;
  75. if (digitalRead(21) == HIGH) btns+=64;
  76. if (digitalRead(23) == HIGH) btns+=128;
  77. setcolmask(29,btns);
  78. setcolmask(30,btns);
  79. setcolmask(31,btns);
  80. ledMatrix.commit();
  81. delay(100);
  82. }
  83. }
  84.  
  85. //sets an LED column according to bitmask
  86. void setcolmask(int col, char bits)
  87. {
  88. for (int i=0; i<8; i++)
  89. {
  90. if (bits & (1<<i))
  91. ledMatrix.setPixel(col,i);
  92. }
  93. }
  94.  
  95. //sets an LED column from the bottom up with value 0-8
  96. void setcolbotval(int col, char val)
  97. {
  98. for (int i=0; i<8; i++)
  99. {
  100. int cmp = i+1;
  101. if (val>=cmp)
  102. ledMatrix.setPixel(col,(7-i));
  103. }
  104. }
Add Comment
Please, Sign In to add comment