Millis вместо delay в цикле for
- Войдите на сайт для отправки комментариев
Втр, 05/04/2016 - 20:16
Имеется светодиодная матрица 5х6, управляется через max7219. Бегущий огонь по 2 и 4 столбцу. Хочу заменить delay на millis, но ничего не получается. Может кто подскажет как это сделать?
#include "LedControl.h" // need the library
LedControl lc=LedControl(12,6,5,1); //
void setup()
{
// the zero refers to the MAX7219 number, it is zero for 1 chip
lc.shutdown(0,false);// turn off power saving, enables display
lc.setIntensity(0,2);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
}
void loop()
{
for (int row=0; row<6; row++ )
{
lc.setLed(0,1,row,true); // turns on LED at col, row
lc.setLed(0,3,row,true); // turns on LED at col, row
delay(25);
}
for (int row=0; row<6; row++)
{
lc.setLed(0,1,row,false); // turns off LED at col, row
lc.setLed(0,3,row,false); // turns off LED at col, row
delay(25);
}
}
Как-то так
#define DELAY 25 unsigned long timer; int row = 0; byte st = 0; void loop() { if (millis()-timer > DELAY) { timer = millis(); lc.setLed(0,1, row, st); // turns on/off LED at col, row lc.setLed(0,3, row, st); // turns on/off LED at col, row if (++row > 6) {row=0; st^=1;} } }Спасибо большое, попробую.