Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LedControl.h>
- #undef round
- // Teeces V3 Basic Sketch (**UNTESTED**)
- // joymonkey added: With dumbed-down easily configured options at the start,
- // so you can easily adjust chain order, brightness and speeds.
- // Michael Smith (michael@badweasel.com) converted it to do a sliding pattern on the PSI's
- // (PSI's LEDs should be in a checkerboard color pattern)
- // Define devices here. Change these numbers depending on
- // what order you have everything connected in the chain.
- int rld1dev=0; //first LED driver on RLD
- int rld2dev=1; //second LED driver on RLD
- int rld3dev=2; //third LED driver on RLD
- //
- int psi1dev=3; //LED driver on Rear (Green/Yellow) PSI
- int psi2dev=4; //LED driver on Front (Red/Blue) PSI
- //
- int fld1dev=5; //LED driver on FLD 1
- int fld2dev=6; //LED driver on FLD 2
- int fld3dev=7; //LED driver on FLD 3
- int fld4dev=8; //LED driver on FLD 4
- //
- // Logic Display settings...
- int rldbright=12; // RLD brightness (0 to 15)
- int fldbright=7; // FLD brightness (0 to 15)
- int logicdelay=175; // adjust this number to change the speed of the logic patterns (lower is faster)
- //
- // PSI settings...
- int psibright=15; // PSI brightness (0 to 15)
- int red=2000; // time (in milliseconds) to stay red (default is 2000)
- int blue=1000; // time (in milliseconds) to stay blue (default is 1000)
- int rbSlide=200; // mts - time to transition between red and blue in slide mode
- int yellow=1000; // time (in milliseconds) to stay yellow (default is 1000)
- int green=2000; // time (in milliseconds) to stay green (default is 2000)
- int ygSlide=200; // mts - time to transition between yellow and green in slide mode
- bool PSISlide=true; // mts - if FALSE will flash back and forth the old way
- // this pattern is the secret sauce for the PSI... I had to declare global here cause for some reason you can't assign it inside a class.
- static const int patternAtStage[] = { B01010000, B11010000, B10010000, B10110000, B10100000, B00100000, B01100000, B01000000, B01010000 };
- //
- // We're done with setting numbers.
- // We shouldn't have to change anything below here.
- //
- class PSI
- {
- bool state;
- int stage;
- unsigned long timeLast;
- int delay1, delay2, delay3;
- int device;
- int delayAtStage[9];
- int slideDirection; // is either 1 or -1
- int maxStage; // for PSIslide it's either 5 or 9 stages, for traditional PSI it's just back and forth between 2
- public:
- // Michael Smith - modified this to have a 3rd delay for the transition time between red and blue
- // the slide cycle is RED, LtoR transition to blue (3 steps), BLUE, LtoR transition to red (3 steps), RED.
- // then it reverses direction and does that cycle in reverse.
- // the LED pattern on a traditional PSI are
- // x R B x
- // R R B B
- // R R B B
- // x R B x
- // the LED pattern on my sliding PSI is checkerboarded:
- // pattern: red on: blue on:
- // x R B x 0101---- 1010----
- // R B R B 1010---- 0101----
- // B R B R 0101---- 1010----
- // x B R x 1010---- 0101----
- // even lines are the inverse of the odd lines. So even = ~odd; (bitwise NOT)
- PSI(int _delay1, int _delay2, int _delay3, int _device)
- {
- delayAtStage[0] = _delay1;
- delayAtStage[1] = _delay3/3; // delay3 is total transition time - divide it by the 3 stages of transition
- delayAtStage[2] = delayAtStage[1];
- delayAtStage[3] = delayAtStage[1];
- delayAtStage[4] = _delay2;
- delayAtStage[5] = delayAtStage[1];
- delayAtStage[6] = delayAtStage[1];
- delayAtStage[7] = delayAtStage[1];
- delayAtStage[8] = _delay1; // repeated because it's not a loop it cycles back and forth across the pattern.
- stage=0;
- slideDirection=1;
- maxStage=8; // change to 5 would skip the LtoR from blue to red.
- timeLast=0;
- device=_device;
- // legacy for traditional PSI animation
- delay1=_delay1;
- delay2=_delay2;
- delay3=_delay3;
- state=false;
- }
- void Animate(unsigned long timeNow, LedControl control)
- {
- if (PSISlide)
- {
- if ((timeNow - timeLast) < delayAtStage[stage]) return;
- //Serial.begin(9600);
- //Serial.println(stage);
- //Serial.println(patternAtStage[stage]);
- timeLast = timeNow;
- stage+=slideDirection; //move to the next stage, which could be up or down in the array
- if (stage >= maxStage)
- {
- // limit the stage to the maxStage and reverse the direction of the slide
- stage=maxStage;
- slideDirection = -1;
- }
- else if (stage <= 0)
- {
- stage=0;
- slideDirection = 1;
- }
- // set the patterns for this stage
- control.setRow(device,0,patternAtStage[stage]);
- control.setRow(device,1,~patternAtStage[stage]);
- control.setRow(device,2,patternAtStage[stage]);
- control.setRow(device,3,~patternAtStage[stage]);
- }
- else
- {
- // this is the original flip flop and assumes the original LED pattern
- if (state && (timeNow - timeLast) < delay1) return;
- if (!state && (timeNow - timeLast) < delay2) return;
- timeLast = timeNow;
- state=!state;
- int cols=B11000000;
- if (state) cols=B00110000;
- for (int row=0; row<4; row++)
- control.setRow(device,row,cols);
- }
- }
- };
- PSI psiFront=PSI(red, blue, rbSlide, psi1dev); //2000 ms on red, 1000 ms on blue.
- PSI psiRear =PSI(yellow, green, ygSlide, psi2dev); //1000 ms on yellow, 2000 ms on green.
- LedControl lc=LedControl(12,11,10,7);
- void setup()
- {
- for(int dev=0;dev<lc.getDeviceCount();dev++)
- {
- lc.shutdown(dev, false); //take the device out of shutdown (power save) mode
- lc.clearDisplay(dev);
- }
- lc.setIntensity(rld1dev, rldbright); //RLD
- lc.setIntensity(rld2dev, rldbright); //RLD
- lc.setIntensity(rld3dev, rldbright); //RLD
- lc.setIntensity(fld1dev, fldbright); //FLD
- lc.setIntensity(fld2dev, fldbright); //FLD
- lc.setIntensity(fld3dev, fldbright); //FLD
- lc.setIntensity(fld4dev, fldbright); //FLD
- lc.setIntensity(psi1dev, psibright); //PSI
- lc.setIntensity(psi2dev, psibright); //PSI
- // pinMode(13, OUTPUT);
- // digitalWrite(13, HIGH);
- //HP lights on constant
- lc.setRow(psi1dev,4,255);
- lc.setRow(psi2dev,4,255);
- }
- void loop()
- {
- unsigned long timeNew= millis();
- psiFront.Animate(timeNew, lc);
- psiRear.Animate(timeNew, lc);
- animateLogic(timeNew);
- }
- void animateLogic(unsigned long timeNow)
- {
- static unsigned long timeLast=0;
- if ((timeNow - timeLast) < logicdelay) return;
- timeLast = timeNow;
- for (int row=0; row<6; row++)
- {
- lc.setRow(rld1dev,row,random(0,256));
- lc.setRow(rld2dev,row,random(0,256));
- lc.setRow(rld3dev,row,random(0,256));
- lc.setRow(fld1dev,row,random(0,256));
- lc.setRow(fld2dev,row,random(0,256));
- lc.setRow(fld3dev,row,random(0,256));
- lc.setRow(fld4dev,row,random(0,256));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement