Arduino - Arduino Contador con Matriz Led 8x32 - Se tilda la pantalla

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 51 puestos en Arduino (en relación al último mes)
Gráfica de Arduino

Arduino Contador con Matriz Led 8x32 - Se tilda la pantalla

Publicado por Marcos (1 intervención) el 30/05/2019 04:36:57
Buen dia, estoy diseñando un Countdown y me paso que a veces la Matriz de Led 8x32 se me prenden todos los led y se queda tildada.

Materiales que use:
Arduino Nano, Matriz led 8x32

Programa:
Contador de tiempo de descarga en una playa de vehiculos, la idea es que la Matriz muestra el tiempo restante que tiene un vehiculo en la playa de descarga, al pasar el tiempo (15:00 min), se vuelve a reiniciar y prende una luz Roja avisando que el tiempo finalizo.

Adjunto las imagenes


Funciodando bien.jgp (aca el Countdown funciona perfecto)
Falla a solucionar.jpg (aca es cuando se me tilda a veces)

alguien sabe el motivo por el cual pasa esto?
si es de ayuda adjunto el codigo del programa

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#include <Bounce2.h> // semaforo
#include <MD_MAX72xx.h>
#include <SPI.h>
 
#define  PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }
#define MAX_DEVICES 4
#define CLK_PIN   13  // or SCK
#define  CS_PIN   10  // or SS
#define DATA_PIN  11  // or MOSI
 
MD_MAX72XX mx = MD_MAX72XX(CS_PIN, MAX_DEVICES); // SPI hardware interface
#define CHAR_SPACING  1 // pixels between characters
 
#define BUF_SIZE  75 // Global message buffers shared by Serial and Scrolling functions
char* MESSAGE;
bool newMessageAvailable = true;
String initTime = "15:00";
String inputString = "";
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 1000;           // interval at which to blink (milliseconds)
 
unsigned long previousMillisB = 0;        // will store last time LED was updated
const long intervalB = 130;           // interval at which to blink (milliseconds)
 
int seconds = 0;
int minutes = 0;
String strSec;
String strMin;
String Data;
bool InicioConteo = false;
 
bool set = false;
String blinkDigit1;
String blinkDigit2;
String blinkDigit3;
String blinkDigit4;
 
String strSec1;
String strSec2;
String strMin1;
String strMin2;
 
int val = 0;
int runStart = true;
bool acceptOne = true;
 
bool buzzOnce = true;
 
String saveData ="";
int i = 0;
 
int iniciarConteo = 5;
 
int iniciarConteoState = LOW;
int sensorPin = 6;
int redPin = 3;                             // semaforo
int greenPin = 4;                           // semaforo
int contadorPin = 7;
unsigned long TIEMPOPULSADO = 0;            // semaforo
unsigned long TiempoReseteo = 0;            // semaforo
byte TEMP = 0;                              // semaforo
Bounce debouncer = Bounce();                // semaforo
 
 
void setup()
{
  pinMode(iniciarConteo,INPUT);
 
 
  mx.begin();
  Serial.begin(57600);
  Serial.print("\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline" ); // 
 
 
  pinMode(redPin, OUTPUT);                // semaforo
  pinMode(greenPin, OUTPUT);                // semaforo
  pinMode(contadorPin, OUTPUT);
  pinMode(redPin, HIGH);                   // semaforo
  pinMode(greenPin, HIGH);                // semaforo
  pinMode(contadorPin,HIGH);
  pinMode(sensorPin, INPUT);              // semaforo 
  debouncer.attach(sensorPin);             // semaforo
  debouncer.interval(50);                   // semaforo
 
}
 
void loop() {
debouncer.update();                                  // Actualizar los estados Bounce
 
  int valor1 = debouncer.read();
 
 if (!valor1) {
      TIEMPOPULSADO = millis();
      TEMP = 1;
      digitalWrite(contadorPin,HIGH);
 
 
 }
     greenPinSecuencia();
   redPinSecuencia ();
    contadorPinSecuencia ();
    Cronometro ();
 
 }
 
 void greenPinSecuencia () {
  if(digitalRead(sensorPin)== HIGH){
    digitalWrite(greenPin, LOW);
 
  }
 
  else{
    digitalWrite(greenPin, HIGH);
 
  } }
 
   void redPinSecuencia () {
  if (millis()>TIEMPOPULSADO+901000 && TEMP){
    digitalWrite(redPin, LOW);
 
  }
 
  else{
 
    digitalWrite(redPin, HIGH);
 
  } }
   void contadorPinSecuencia () {
 
    if ((millis()>TIEMPOPULSADO && millis () < TIEMPOPULSADO+900000)
    || (millis()>TIEMPOPULSADO+900100 && millis () < TIEMPOPULSADO+1800000)
    || (millis()>TIEMPOPULSADO+1800100 && millis () < TIEMPOPULSADO+2700000)
    || (millis()>TIEMPOPULSADO+2700100 && millis () < TIEMPOPULSADO+3600000)
    || (millis()>TIEMPOPULSADO+3600100 && millis () < TIEMPOPULSADO+4500000)
    || (millis()>TIEMPOPULSADO+4500100 && millis () < TIEMPOPULSADO+5400000)
    || (millis()>TIEMPOPULSADO+5400100 && millis () < TIEMPOPULSADO+6300000)
    || (millis()>TIEMPOPULSADO+6300100 && millis () < TIEMPOPULSADO+7200000)
    || (millis()>TIEMPOPULSADO+7200100 && millis () < TIEMPOPULSADO+8100000)
    || (millis()>TIEMPOPULSADO+8100100 && millis () < TIEMPOPULSADO+9000000)
    || (millis()>TIEMPOPULSADO+9000100 && millis () < TIEMPOPULSADO+10000000)
    || (millis()>TIEMPOPULSADO+10000100 && millis () < TIEMPOPULSADO+10900100)
    )
 
    {
         digitalWrite(contadorPin, LOW);
 
      }
 else{
 
  digitalWrite(contadorPin, HIGH);
  TiempoReseteo = millis ();
  }
  }
void Cronometro ()
{
 
      if(digitalRead(iniciarConteo)== HIGH){
          minutes = (initTime.substring(0,3)).toInt();
          seconds = (initTime.substring(3,5)).toInt()+1;
          InicioConteo = false;
     }
 
     pauseStartMethod();
}
void pauseStartMethod()
{
   if(iniciarConteoState == HIGH){
    if(set==true)
    {
      minutes = (blinkDigit1+blinkDigit2).toInt();
      seconds= (blinkDigit3+blinkDigit4).toInt();
      }
    set = false;
        i = 0;
        if (acceptOne == true)
        {
            Serial.println(iniciarConteoState);
            if (val == 0){
                runStart = false;
                val = 1;
            }else{
                runStart =true;
                val = 0;
            }
            acceptOne = false;
        }
 
    }else{
        if(runStart == true && set == false){
            Timer();
        }
          acceptOne= true;
     }
  }
 
void Timer(){
  unsigned long currentMillis = millis();
 
  if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
 
      if(minutes == 0 && seconds == 0)
      {
          if (buzzOnce == true){
 
          }
        }else{
      buzzOnce = true;
      seconds--;
      if(seconds == -1){
        if(minutes != 0){
            minutes--;
            seconds = 59;
            }
         }
         processTime();
         printTime();
       }
  }
  }
 
void processTime(){
      strSec = String(seconds);
      strMin = String(minutes);
 
      if(String(seconds).length() == 1)
      {
        strSec = "0"+String(seconds);
      }
      if(String(minutes).length() == 1)
      {
        strMin = "0"+String(minutes);
        }
 
      Data= strMin+ ":"+ strSec;
}
 
void printTime()
{
  String printData = " "+strMin+ ":"+ strSec;
  char copy[50];
  printData.toCharArray(copy, 50);
  MESSAGE = copy;// message Content
 
  PRINT("\nProcessing new message: ", MESSAGE);
  printText(0, MAX_DEVICES-1, MESSAGE);
}
 
void printText(uint8_t modStart, uint8_t modEnd, char *pMsg)
 
{
  uint8_t   state = 0;
  uint8_t    curLen;
  uint16_t  showLen;
  uint8_t   cBuf[8];
  int16_t   col = ((modEnd + 1) * COL_SIZE) - 1;
 
  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
 
  do
  {
    switch(state)
    {
      case 0: // Load the next character from the font table
 
        if (*pMsg == '\0')
        {
          showLen = col - (modEnd * COL_SIZE);  // padding characters
          state = 2;
          break;
        }
 
 
        showLen = mx.getChar(*pMsg++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
        curLen = 0;
        state++;
 
 
      case 1: // display the next part of the character
        mx.setColumn(col--, cBuf[curLen++]);
 
 
        if (curLen == showLen)
        {
          showLen = CHAR_SPACING;
          state = 2;
        }
        break;
 
      case 2:
        curLen = 0;
        state++;
        // fall through
 
      case 3:         mx.setColumn(col--, 0);
        curLen++;
        if (curLen == showLen)
          state = 0;
        break;
 
      default:
        col = -1;
    }
  } while (col >= (modStart * COL_SIZE));
 
  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::ON);

Muchas gracias a quien me brinde su tiempo.
la verdad que no le encuentro cual es el error. o si es un error comun de principiante y me olvide de algo esencial.

ahora me voy a poner a buscar un programa para dibujar el diagrama de circuito y tambien subirlo a ver si el problema es en la conexión.

Muchas Gracias!!
Funcionando-Bien
Falla-a-solucionar
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder