SHOW:
|
|
- or go back to the newest paste.
| 1 | // | |
| 2 | - | // Teeces V3 Sketch for Arduino Pro Mini with 2 chains |
| 2 | + | // Teeces V3.1 Sketch for Arduino Pro Micro with 2 chains |
| 3 | // with John V's PSI slide method (using the standard PSI LED pattern) | |
| 4 | // Boards should be hooked up like this... | |
| 5 | // RLD OUT1 -> Rear PSI | |
| 6 | // RLD OUT2 -> FLD -> FLD -> Front PSI | |
| 7 | // Note: RLD OUT2 is only on the newer v3.1 boards. If you have an earlier v3.0 board | |
| 8 | // you can use Arduino pins 9, 8 and 7 and +5 and GND for the front chain. | |
| 9 | - | // If you're using an Arduino Pro Micro instead of a Pro Mini, you'll need to |
| 9 | + | // If you're using an Arduino Pro Mini instead of a Pro Micro, you'll need to |
| 10 | // adjust the LedControl lines. | |
| 11 | // | |
| 12 | ||
| 13 | #include <LedControl.h> | |
| 14 | #undef round | |
| 15 | ||
| 16 | class PSI | |
| 17 | {
| |
| 18 | int stage; //0 thru 4 | |
| 19 | int inc; | |
| 20 | int stageDelay[5]; | |
| 21 | int cols[5]; | |
| 22 | ||
| 23 | unsigned long timeLast; | |
| 24 | int device; | |
| 25 | ||
| 26 | public: | |
| 27 | ||
| 28 | PSI(int _delay1, int _delay2, int _device) | |
| 29 | {
| |
| 30 | device=_device; | |
| 31 | ||
| 32 | stage=0; | |
| 33 | timeLast=0; | |
| 34 | inc=1; | |
| 35 | ||
| 36 | cols[0] = B11000000; | |
| 37 | cols[1] = B11100000; | |
| 38 | cols[2] = B01100000; | |
| 39 | cols[3] = B01110000; | |
| 40 | cols[4] = B00110000; | |
| 41 | ||
| 42 | stageDelay[0] = _delay1 - 300; | |
| 43 | stageDelay[1] = 100; | |
| 44 | stageDelay[2] = 100; | |
| 45 | stageDelay[3] = 100; | |
| 46 | stageDelay[4] = _delay2 - 300; | |
| 47 | } | |
| 48 | ||
| 49 | void Animate(unsigned long elapsed, LedControl control) | |
| 50 | {
| |
| 51 | if ((elapsed - timeLast) < stageDelay[stage]) return; | |
| 52 | ||
| 53 | timeLast = elapsed; | |
| 54 | stage+=inc; | |
| 55 | ||
| 56 | if (stage>4 || stage<0 ) | |
| 57 | {
| |
| 58 | inc *= -1; | |
| 59 | stage+=inc*2; | |
| 60 | } | |
| 61 | ||
| 62 | for (int row=0; row<4; row++) | |
| 63 | control.setRow(device,row,cols[stage]); | |
| 64 | } | |
| 65 | }; | |
| 66 | ||
| 67 | PSI psiFront=PSI(2500, 1700, 2); //2000 ms on red, 1000 ms on blue. device is 2 | |
| 68 | PSI psiRear =PSI(1700, 2500, 3); //1000 ms on yellow, 2000 ms on green. device is 3 | |
| 69 | - | LedControl lc=LedControl(12,11,10,4); //rear chain when using Arduino Pro Mini |
| 69 | + | LedControl lc=LedControl(14,16,10,4); //rear chain |
| 70 | - | //LedControl lc=LedControl(14,16,10,4); //rear chain when using Arduino Pro Micro |
| 70 | + | |
| 71 | ||
| 72 | void setup() | |
| 73 | {
| |
| 74 | for(int dev=0;dev<lc.getDeviceCount();dev++) | |
| 75 | {
| |
| 76 | lc.shutdown(dev, false); //take the device out of shutdown (power save) mode | |
| 77 | lc.clearDisplay(dev); | |
| 78 | } | |
| 79 | for(int dev=0;dev<lc2.getDeviceCount();dev++) | |
| 80 | {
| |
| 81 | lc2.shutdown(dev, false); //take the device out of shutdown (power save) mode | |
| 82 | lc2.clearDisplay(dev); | |
| 83 | } | |
| 84 | ||
| 85 | lc.setIntensity(0, 7); //RLD (RLD brightness is 7 by default. change to 15 for blinding bright) | |
| 86 | - | lc.setIntensity(0, 7); //RLD |
| 86 | + | |
| 87 | lc.setIntensity(2, 7); //RLD | |
| 88 | lc.setIntensity(3, 15); //Rear PSI | |
| 89 | ||
| 90 | lc2.setIntensity(0, 5); //FLD (FLD brightness is 5 by default. change to 15 for blinding bright) | |
| 91 | - | lc2.setIntensity(0, 5); //FLD |
| 91 | + | |
| 92 | lc2.setIntensity(2, 15); //Front PSI | |
| 93 | ||
| 94 | // pinMode(13, OUTPUT); | |
| 95 | // digitalWrite(13, HIGH); | |
| 96 | ||
| 97 | //HP lights on constant | |
| 98 | lc.setRow(3,4,255); //rear psi | |
| 99 | lc2.setRow(2,4,255); //front psi | |
| 100 | ||
| 101 | pinMode(17, OUTPUT); // Set RX LED as an output | |
| 102 | ||
| 103 | } | |
| 104 | ||
| 105 | void loop() | |
| 106 | {
| |
| 107 | unsigned long timeNew= millis(); | |
| 108 | psiFront.Animate(timeNew, lc2); | |
| 109 | psiRear.Animate(timeNew, lc); | |
| 110 | animateLogic(timeNew); | |
| 111 | microPSI(timeNew); | |
| 112 | - | //microPSI(timeNew); |
| 112 | + | |
| 113 | ||
| 114 | void animateLogic(unsigned long elapsed) | |
| 115 | {
| |
| 116 | static unsigned long timeLast=0; | |
| 117 | if ((elapsed - timeLast) < 200) return; | |
| 118 | timeLast = elapsed; | |
| 119 | ||
| 120 | for (int dev=0; dev<3; dev++) | |
| 121 | for (int row=0; row<6; row++) | |
| 122 | lc.setRow(dev,row,random(0,256)); | |
| 123 | for (int dev=0; dev<2; dev++) | |
| 124 | for (int row=0; row<6; row++) | |
| 125 | lc2.setRow(dev,row,random(0,256)); | |
| 126 | } | |
| 127 | ||
| 128 | int RXLED = 17; | |
| 129 | int ledState = LOW; | |
| 130 | ||
| 131 | void microPSI(unsigned long elapsed) | |
| 132 | - | /*void microPSI(unsigned long elapsed) |
| 132 | + | |
| 133 | //blink the ProMicro's TX and RX LEDs back and forth | |
| 134 | static unsigned long timeLast=0; | |
| 135 | if ((elapsed - timeLast) < 2000) return; | |
| 136 | timeLast = elapsed; | |
| 137 | // if the LED is off turn it on and vice-versa: | |
| 138 | if (ledState == LOW) {
| |
| 139 | ledState = HIGH; | |
| 140 | digitalWrite(17, HIGH); // set the LED on | |
| 141 | TXLED1; //TX LED is not tied to a normally controlled pin | |
| 142 | } | |
| 143 | else {
| |
| 144 | ledState = LOW; | |
| 145 | digitalWrite(17, LOW); // set the LED off | |
| 146 | TXLED0; | |
| 147 | } | |
| 148 | //} | |
| 149 | } |