From ddb4a82165ec230fee64ed631814e172a8ba140a Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sun, 27 Jan 2019 22:12:04 +0100 Subject: [PATCH] add matrix structure --- led.c | 37 +++++++++++++++++++++++++++++++++++-- led.h | 7 ++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/led.c b/led.c index cf013e4..a31f465 100644 --- a/led.c +++ b/led.c @@ -11,6 +11,21 @@ #include +#define SIZE 4 + +tColor matrix[SIZE][SIZE] = { + { OFF, OFF, OFF, OFF }, + { OFF, OFF, OFF, OFF }, + { OFF, OFF, OFF, OFF }, + { OFF, OFF, OFF, OFF } +}; + +void ledSetMatrix(uint8_t col, uint8_t row, tColor color) { + if ((col < SIZE) && (row < SIZE)) { + matrix[col][row] = color; + } +} + /* row0: P1.3 row1: P1.4 @@ -164,7 +179,8 @@ void selectCol(uint8_t column, tColor color) { } } -void ledExec() { +/* +void testledExec() { static uint8_t rowNum = 0; static uint8_t colNum = 0; @@ -186,9 +202,26 @@ void ledExec() { } } } +} +*/ + +void ledExec() { + static uint8_t rowNum = SIZE; + static uint8_t colNum = SIZE; + + colNum++; + if (colNum >= SIZE) { + colNum = 0; + rowNum++; + if (rowNum >= SIZE) { + rowNum = 0; + } + selectRow(rowNum); + } + selectCol(colNum, matrix[colNum][rowNum]); } void ledInit() { - schAdd(ledExec, NULL, 0, 50); + schAdd(ledExec, NULL, 0, 10); } diff --git a/led.h b/led.h index 5c84bdb..f84b3c6 100644 --- a/led.h +++ b/led.h @@ -8,10 +8,15 @@ #ifndef LED_H_ #define LED_H_ + +#include + + typedef enum { BLUE = 0, RED = 1, OFF = 2 } tColor; -void ledExec(); void ledInit(); +void ledSetMatrix(uint8_t col, uint8_t row, tColor color); + #endif /* LED_H_ */