Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Teeces V3 Sketch for Arduino Pro Mini with 2 chains
- // with John V's PSI slide method (using the standard PSI LED pattern)
- // Boards should be hooked up like this...
- // RLD OUT1 -> Rear PSI
- // RLD OUT2 -> FLD -> FLD -> Front PSI
- // Note: RLD OUT2 is only on the newer v3.1 boards. If you have an earlier v3.0 board
- // you can use Arduino pins 9, 8 and 7 and +5 and GND for the front chain.
- // If you're using an Arduino Pro Micro instead of a Pro Mini, you'll need to
- // adjust the LedControl lines.
- //
- #include <LedControl.h>
- #undef round
- class PSI
- {
- int stage; //0 thru 4
- int inc;
- int stageDelay[5];
- int cols[5];
- unsigned long timeLast;
- int device;
- public:
- PSI(int _delay1, int _delay2, int _device)
- {
- device=_device;
- stage=0;
- timeLast=0;
- inc=1;
- cols[0] = B11000000;
- cols[1] = B11100000;
- cols[2] = B01100000;
- cols[3] = B01110000;
- cols[4] = B00110000;
- stageDelay[0] = _delay1 - 300;
- stageDelay[1] = 100;
- stageDelay[2] = 100;
- stageDelay[3] = 100;
- stageDelay[4] = _delay2 - 300;
- }
- void Animate(unsigned long elapsed, LedControl control)
- {
- if ((elapsed - timeLast) < stageDelay[stage]) return;
- timeLast = elapsed;
- stage+=inc;
- if (stage>4 || stage<0 )
- {
- inc *= -1;
- stage+=inc*2;
- }
- for (int row=0; row<4; row++)
- control.setRow(device,row,cols[stage]);
- }
- };
- PSI psiFront=PSI(2500, 1700, 2); //2000 ms on red, 1000 ms on blue. device is 2
- PSI psiRear =PSI(1700, 2500, 3); //1000 ms on yellow, 2000 ms on green. device is 3
- LedControl lc=LedControl(12,11,10,4); //rear chain when using Arduino Pro Mini
- //LedControl lc=LedControl(14,16,10,4); //rear chain when using Arduino Pro Micro
- LedControl lc2=LedControl(9,8,7,3); //front chain for v3.1
- 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);
- }
- for(int dev=0;dev<lc2.getDeviceCount();dev++)
- {
- lc2.shutdown(dev, false); //take the device out of shutdown (power save) mode
- lc2.clearDisplay(dev);
- }
- lc.setIntensity(0, 7); //RLD
- lc.setIntensity(1, 7); //RLD
- lc.setIntensity(2, 7); //RLD
- lc.setIntensity(3, 15); //Rear PSI
- lc2.setIntensity(0, 5); //FLD
- lc2.setIntensity(1, 5); //FLD
- lc2.setIntensity(2, 15); //Front PSI
- // pinMode(13, OUTPUT);
- // digitalWrite(13, HIGH);
- //HP lights on constant
- lc.setRow(3,4,255); //rear psi
- lc2.setRow(2,4,255); //front psi
- pinMode(17, OUTPUT); // Set RX LED as an output
- }
- void loop()
- {
- unsigned long timeNew= millis();
- psiFront.Animate(timeNew, lc2);
- psiRear.Animate(timeNew, lc);
- animateLogic(timeNew);
- //microPSI(timeNew);
- }
- void animateLogic(unsigned long elapsed)
- {
- static unsigned long timeLast=0;
- if ((elapsed - timeLast) < 200) return;
- timeLast = elapsed;
- for (int dev=0; dev<3; dev++)
- for (int row=0; row<6; row++)
- lc.setRow(dev,row,random(0,256));
- for (int dev=0; dev<2; dev++)
- for (int row=0; row<6; row++)
- lc2.setRow(dev,row,random(0,256));
- }
- int RXLED = 17;
- int ledState = LOW;
- /*void microPSI(unsigned long elapsed)
- {
- //blink the ProMicro's TX and RX LEDs back and forth
- static unsigned long timeLast=0;
- if ((elapsed - timeLast) < 2000) return;
- timeLast = elapsed;
- // if the LED is off turn it on and vice-versa:
- if (ledState == LOW) {
- ledState = HIGH;
- digitalWrite(17, HIGH); // set the LED on
- TXLED1; //TX LED is not tied to a normally controlled pin
- }
- else {
- ledState = LOW;
- digitalWrite(17, LOW); // set the LED off
- TXLED0;
- }
- //}
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement