|
| 1 | +// testshapes demo for RGBmatrixPanel library. |
| 2 | +// Demonstrates the drawing abilities of the RGBmatrixPanel library. |
| 3 | +// For 32x32 RGB LED matrix. |
| 4 | + |
| 5 | +// NOTE THIS CAN ONLY BE USED ON A MEGA! NOT ENOUGH RAM ON UNO! |
| 6 | + |
| 7 | +#include <Adafruit_GFX.h> // Core graphics library |
| 8 | +#include <RGBmatrixPanel.h> // Hardware-specific library |
| 9 | + |
| 10 | +// If your 32x32 matrix has the SINGLE HEADER input, |
| 11 | +// use this pinout: |
| 12 | +#define CLK 12 // MUST be on PORTB! |
| 13 | +#define OE 13 |
| 14 | +#define LAT A0 |
| 15 | + |
| 16 | +#define A 10 |
| 17 | +#define B A2 |
| 18 | +#define C 11 |
| 19 | +#define D A1 |
| 20 | + |
| 21 | +RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64); |
| 22 | + |
| 23 | +void setup() { |
| 24 | + |
| 25 | + matrix.begin(); |
| 26 | + |
| 27 | + // draw a pixel in solid white |
| 28 | + matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7)); |
| 29 | + delay(500); |
| 30 | + |
| 31 | + // fix the screen with green |
| 32 | + matrix.fillRect(0, 0, matrix.width(), matrix.height(), matrix.Color333(0, 7, 0)); |
| 33 | + delay(500); |
| 34 | + |
| 35 | + // draw a box in yellow |
| 36 | + matrix.drawRect(0, 0, matrix.width(), matrix.height(), matrix.Color333(7, 7, 0)); |
| 37 | + delay(500); |
| 38 | + |
| 39 | + // draw an 'X' in red |
| 40 | + matrix.drawLine(0, 0, matrix.width()-1, matrix.height()-1, matrix.Color333(7, 0, 0)); |
| 41 | + matrix.drawLine(matrix.width()-1, 0, 0, matrix.height()-1, matrix.Color333(7, 0, 0)); |
| 42 | + delay(500); |
| 43 | + |
| 44 | + // draw a blue circle |
| 45 | + matrix.drawCircle(10, 10, 10, matrix.Color333(0, 0, 7)); |
| 46 | + delay(500); |
| 47 | + |
| 48 | + // fill a violet circle |
| 49 | + matrix.fillCircle(40, 21, 10, matrix.Color333(7, 0, 7)); |
| 50 | + delay(500); |
| 51 | + |
| 52 | + // fill the screen with 'black' |
| 53 | + matrix.fillScreen(matrix.Color333(0, 0, 0)); |
| 54 | + |
| 55 | + // draw some text! |
| 56 | + matrix.setTextSize(1); // size 1 == 8 pixels high |
| 57 | + matrix.setTextWrap(false); // Don't wrap at end of line - will do ourselves |
| 58 | + |
| 59 | + matrix.setCursor(8, 0); // start at top left, with 8 pixel of spacing |
| 60 | + uint8_t w = 0; |
| 61 | + char *str = "AdafruitIndustries"; |
| 62 | + for (w=0; w<8; w++) { |
| 63 | + matrix.setTextColor(Wheel(w)); |
| 64 | + matrix.print(str[w]); |
| 65 | + } |
| 66 | + matrix.setCursor(2, 8); // next line |
| 67 | + for (w=8; w<18; w++) { |
| 68 | + matrix.setTextColor(Wheel(w)); |
| 69 | + matrix.print(str[w]); |
| 70 | + } |
| 71 | + matrix.println(); |
| 72 | + //matrix.setTextColor(matrix.Color333(4,4,4)); |
| 73 | + //matrix.println("Industries"); |
| 74 | + matrix.setTextColor(matrix.Color333(7,7,7)); |
| 75 | + matrix.println("LED MATRIX!"); |
| 76 | + |
| 77 | + // print each letter with a rainbow color |
| 78 | + matrix.setTextColor(matrix.Color333(7,0,0)); |
| 79 | + matrix.print('3'); |
| 80 | + matrix.setTextColor(matrix.Color333(7,4,0)); |
| 81 | + matrix.print('2'); |
| 82 | + matrix.setTextColor(matrix.Color333(7,7,0)); |
| 83 | + matrix.print('x'); |
| 84 | + matrix.setTextColor(matrix.Color333(4,7,0)); |
| 85 | + matrix.print('6'); |
| 86 | + matrix.setTextColor(matrix.Color333(0,7,0)); |
| 87 | + matrix.print('4'); |
| 88 | + matrix.setCursor(34, 24); |
| 89 | + matrix.setTextColor(matrix.Color333(0,7,7)); |
| 90 | + matrix.print("*"); |
| 91 | + matrix.setTextColor(matrix.Color333(0,4,7)); |
| 92 | + matrix.print('R'); |
| 93 | + matrix.setTextColor(matrix.Color333(0,0,7)); |
| 94 | + matrix.print('G'); |
| 95 | + matrix.setTextColor(matrix.Color333(4,0,7)); |
| 96 | + matrix.print("B"); |
| 97 | + matrix.setTextColor(matrix.Color333(7,0,4)); |
| 98 | + matrix.println("*"); |
| 99 | + |
| 100 | + |
| 101 | + // whew! |
| 102 | +} |
| 103 | + |
| 104 | +void loop() { |
| 105 | + // do nothing |
| 106 | +} |
| 107 | + |
| 108 | + |
| 109 | +// Input a value 0 to 24 to get a color value. |
| 110 | +// The colours are a transition r - g - b - back to r. |
| 111 | +uint16_t Wheel(byte WheelPos) { |
| 112 | + if(WheelPos < 8) { |
| 113 | + return matrix.Color333(7 - WheelPos, WheelPos, 0); |
| 114 | + } else if(WheelPos < 16) { |
| 115 | + WheelPos -= 8; |
| 116 | + return matrix.Color333(0, 7-WheelPos, WheelPos); |
| 117 | + } else { |
| 118 | + WheelPos -= 16; |
| 119 | + return matrix.Color333(0, WheelPos, 7 - WheelPos); |
| 120 | + } |
| 121 | +} |
0 commit comments