Advertisement
joymonkey

Teeces V3 Basic Sketch with Teeces' PSI Slide Method

Mar 28th, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1. //
  2. // Teeces V3 Sketch for Arduino Pro Mini with 1 chain (RLD->FLD->FLD->PSI->PSI)
  3. // with John V's PSI slide method (using the standard PSI LED pattern)
  4. //
  5.  
  6. #include <LedControl.h>
  7. #undef round
  8.  
  9. class PSI
  10. {
  11.   int stage; //0 thru 4
  12.   int inc;
  13.   int stageDelay[5];
  14.   int cols[5];
  15.  
  16.   unsigned long timeLast;
  17.   int device;
  18.  
  19.   public:
  20.  
  21.   PSI(int _delay1, int _delay2, int _device)
  22.   {
  23.     device=_device;
  24.    
  25.     stage=0;
  26.     timeLast=0;
  27.     inc=1;
  28.    
  29.     cols[0] = B11000000;
  30.     cols[1] = B11100000;
  31.     cols[2] = B01100000;
  32.     cols[3] = B01110000;
  33.     cols[4] = B00110000;
  34.    
  35.     stageDelay[0] = _delay1 - 300;
  36.     stageDelay[1] = 100;
  37.     stageDelay[2] = 100;
  38.     stageDelay[3] = 100;
  39.     stageDelay[4] = _delay2 - 300;
  40.   }
  41.  
  42.   void Animate(unsigned long elapsed, LedControl control)
  43.   {
  44.     if ((elapsed - timeLast) < stageDelay[stage]) return;
  45.    
  46.     timeLast = elapsed;
  47.     stage+=inc;
  48.  
  49.     if (stage>4 || stage<0 )
  50.     {
  51.       inc *= -1;
  52.       stage+=inc*2;
  53.     }
  54.    
  55.     for (int row=0; row<4; row++)
  56.       control.setRow(device,row,cols[stage]);
  57.   }
  58. };
  59.  
  60. PSI psiFront=PSI(2000, 1000, 5); //2000 ms on red, 1000 ms on blue.  device is 5
  61. PSI psiRear =PSI(1000, 2000, 6); //1000 ms on yellow, 2000 ms on green.  device is 6
  62. LedControl lc=LedControl(12,11,10,7);
  63.  
  64. void setup()
  65. {
  66.   for(int dev=0;dev<lc.getDeviceCount();dev++)
  67.   {
  68.     lc.shutdown(dev, false); //take the device out of shutdown (power save) mode
  69.     lc.clearDisplay(dev);
  70.   }
  71.  
  72.   lc.setIntensity(0, 7); //RLD
  73.   lc.setIntensity(1, 7); //RLD
  74.   lc.setIntensity(2, 7); //RLD
  75.   lc.setIntensity(3, 5);  //FLD
  76.   lc.setIntensity(4, 5);  //FLD
  77.   lc.setIntensity(5, 15); //PSI
  78.   lc.setIntensity(6, 15); //PSI
  79.  
  80.  
  81. //  pinMode(13, OUTPUT);
  82. //  digitalWrite(13, HIGH);
  83.  
  84.   //HP lights on constant
  85.   lc.setRow(5,4,255);
  86.   lc.setRow(6,4,255);
  87.  
  88. }
  89.  
  90. void loop()
  91. {
  92.   unsigned long timeNew= millis();
  93.   psiFront.Animate(timeNew, lc);
  94.   psiRear.Animate(timeNew, lc);
  95.   animateLogic(timeNew);
  96. }
  97.  
  98. void animateLogic(unsigned long elapsed)
  99. {
  100.   static unsigned long timeLast=0;
  101.   if ((elapsed - timeLast) < 200) return;
  102.   timeLast = elapsed;
  103.  
  104.   for (int dev=0; dev<5; dev++)
  105.     for (int row=0; row<6; row++)
  106.       lc.setRow(dev,row,random(0,256));
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement