Created
March 12, 2017 08:48
-
-
Save anonymous/56c345a14009ef5414cc7291e115d0e1 to your computer and use it in GitHub Desktop.
interrupt implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern “C" | |
{ | |
#include “user_interface.h" | |
} | |
#define NUM 10 | |
#define COL 4 | |
#define ROW 6 | |
os_timer_t myTimer; | |
const int col[COL] = {0,1,2,3}; | |
const int row[ROW] = {4,5,12,13,14,15}; | |
// three-dimensional array for pattern of number 0-9 | |
int number[NUM][COL][ROW] = | |
{ | |
// zero | |
{{1,1,1,1,1,0}, | |
{1,0,0,0,1,0}, | |
{1,1,1,1,1,0}, | |
{0,0,0,0,0,0}}, | |
// one | |
{{0,0,0,0,0,0}, | |
{0,0,0,0,0,0}, | |
{1,1,1,1,1,0}, | |
{0,0,0,0,0,0}}, | |
// two | |
{{1,0,1,1,1,0}, | |
{1,0,1,0,1,0}, | |
{1,1,1,0,1,0}, | |
{0,0,0,0,0,0}}, | |
// three | |
{{1,0,1,0,1,0}, | |
{1,0,1,0,1,0}, | |
{1,1,1,1,1,0}, | |
{0,0,0,0,0,0}}, | |
// four | |
{{1,1,1,0,0,0}, | |
{0,0,1,0,0,0}, | |
{1,1,1,1,1,0}, | |
{0,0,0,0,0,0}}, | |
// five | |
{{1,1,1,0,1,0}, | |
{1,0,1,0,1,0}, | |
{1,0,1,1,1,0}, | |
{0,0,0,0,0,0}}, | |
// six | |
{{1,1,1,1,1,0}, | |
{1,0,1,0,1,0}, | |
{1,0,1,1,1,0}, | |
{0,0,0,0,0,0}}, | |
// seven | |
{{1,0,0,0,0,0}, | |
{1,0,0,0,0,0}, | |
{1,1,1,1,1,0}, | |
{0,0,0,0,0,0}}, | |
// eight | |
{{1,1,1,1,1,0}, | |
{1,0,1,0,1,0}, | |
{1,1,1,1,1,0}, | |
{0,0,0,0,0,0}}, | |
//nine | |
{{1,1,1,0,0,0}, | |
{1,0,1,0,0,0}, | |
{1,1,1,1,1,0}, | |
{0,0,0,0,0,0}} | |
}; | |
int pixel[NUM][COL][ROW]; // the empty dimension array use in the loop | |
unsigned long changeNumber = 0; // the variable detected for each number | |
void timerCallback(void *pArg) // detect each col and row | |
{ | |
static int x=0, y; // the variable for the pixel | |
// x represent column | |
// y represent row | |
if (x == 0) | |
{ | |
digitalWrite(col[COL-1], LOW); | |
digitalWrite(col[x], HIGH); | |
for (y = 0; y <= 5; y++) | |
{ | |
int light = pixel[changeNumber][x][y]; | |
if (light == 1) | |
digitalWrite(row[y], LOW); | |
else | |
digitalWrite(row[y], HIGH); | |
} | |
x++; | |
} | |
else | |
{ | |
digitalWrite(col[x-1], LOW); | |
digitalWrite(col[x], HIGH); | |
for (y = 0; y <= 5; y++) | |
{ | |
int light = pixel[changeNumber][x][y]; | |
if (light == 1) | |
digitalWrite(row[y], LOW); | |
else | |
digitalWrite(row[y], HIGH); | |
} | |
if (x == COL-1) | |
x = 0; | |
else | |
x++; | |
} | |
} | |
void user_init(void) | |
{ | |
os_timer_setfn(&myTimer, timerCallback, NULL); | |
os_timer_arm(&myTimer, 1, true); | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
int i; | |
for (i=0;i<=3;i++) | |
{ | |
pinMode(col[i], OUTPUT); // initialize pin mode as output | |
digitalWrite(col[i],LOW); // initialize pin stat, anode = LOW -> off | |
} | |
for (i=0;i<=5;i++) | |
{ | |
pinMode(row[i], OUTPUT); // pin mode as output | |
digitalWrite(row[i],HIGH); // cathode = HIGH -> off | |
} | |
user_init(); //to spark the callback function | |
} | |
void loop() | |
{ | |
int i, k; | |
for (i = 0; i < COL; i++) // show something in the LED board | |
{ | |
for (k = 0; k < ROW; k++) | |
{ | |
pixel[changeNumber][i][k] = number[changeNumber][i][k]; // let pixel work on the the number which depends “changeNumber" | |
} | |
} | |
delay(500); // each number showing on the LED board will last for 500 millisec | |
if (changeNumber == NUM-1) | |
changeNumber = 0; | |
else | |
changeNumber++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment