View difference between Paste ID: ZWgLJyKb and ami54MHh
SHOW: | | - or go back to the newest paste.
1
//
2-
// Teeces V3 Sketch for Arduino Pro Mini with 1 chain (RLD->FLD->FLD->PSI->PSI)
2+
// Teeces V3 Sketch for Arduino Pro Mini 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
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-
PSI psiFront=PSI(2000, 1000, 5); //2000 ms on red, 1000 ms on blue.  device is 5
60+
61-
PSI psiRear =PSI(1000, 2000, 6); //1000 ms on yellow, 2000 ms on green.  device is 6
61+
62-
LedControl lc=LedControl(12,11,10,7); 
62+
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
70
//LedControl lc=LedControl(14,16,10,4); //rear chain when using Arduino Pro Micro
71
LedControl lc2=LedControl(9,8,7,3); //front chain for v3.1
72
73
void setup()
74
{
75-
  lc.setIntensity(3, 5);  //FLD
75+
76-
  lc.setIntensity(4, 5);  //FLD
76+
77-
  lc.setIntensity(5, 15); //PSI
77+
78-
  lc.setIntensity(6, 15); //PSI
78+
79
  }
80
  for(int dev=0;dev<lc2.getDeviceCount();dev++)
81
  {
82
    lc2.shutdown(dev, false); //take the device out of shutdown (power save) mode
83
    lc2.clearDisplay(dev);
84
  }
85-
  lc.setRow(5,4,255);
85+
86-
  lc.setRow(6,4,255);
86+
87
  lc.setIntensity(1, 7); //RLD
88
  lc.setIntensity(2, 7); //RLD
89
  lc.setIntensity(3, 15); //Rear PSI
90
  
91
  lc2.setIntensity(0, 5);  //FLD
92
  lc2.setIntensity(1, 5);  //FLD  
93-
  psiFront.Animate(timeNew, lc);
93+
  lc2.setIntensity(2, 15); //Front PSI
94
  
95
//  pinMode(13, OUTPUT);
96
//  digitalWrite(13, HIGH);
97
98
  //HP lights on constant
99
  lc.setRow(3,4,255); //rear psi
100
  lc2.setRow(2,4,255); //front psi
101
  
102
  pinMode(17, OUTPUT);  // Set RX LED as an output
103
  
104-
  for (int dev=0; dev<5; dev++)
104+
105
106
void loop()
107-
}
107+
108
  unsigned long timeNew= millis();
109
  psiFront.Animate(timeNew, lc2);
110
  psiRear.Animate(timeNew, lc);
111
  animateLogic(timeNew);
112
  //microPSI(timeNew);
113
}
114
115
void animateLogic(unsigned long elapsed)
116
{
117
  static unsigned long timeLast=0;
118
  if ((elapsed - timeLast) < 200) return;
119
  timeLast = elapsed; 
120
121
  for (int dev=0; dev<3; dev++)
122
    for (int row=0; row<6; row++)
123
      lc.setRow(dev,row,random(0,256));
124
  for (int dev=0; dev<2; dev++)
125
    for (int row=0; row<6; row++)
126
      lc2.setRow(dev,row,random(0,256));      
127
}
128
129
int RXLED = 17; 
130
int ledState = LOW;
131
132
/*void microPSI(unsigned long elapsed)
133
{
134
  //blink the ProMicro's TX and RX LEDs back and forth
135
  static unsigned long timeLast=0;
136
  if ((elapsed - timeLast) < 2000) return;
137
    timeLast = elapsed; 
138
    // if the LED is off turn it on and vice-versa:
139
    if (ledState == LOW) {
140
      ledState = HIGH;
141
      digitalWrite(17, HIGH);   // set the LED on
142
      TXLED1; //TX LED is not tied to a normally controlled pin
143
    }
144
    else {
145
      ledState = LOW;
146
      digitalWrite(17, LOW);    // set the LED off
147
      TXLED0;
148
    }
149
  //}
150
}*/