0% found this document useful (0 votes)
5 views

Arduino

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Arduino

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

const int row[8] = {

2, 7, 19, 5, 13, 18, 12, 16


};

// 2-dimensional array of column pin numbers:


const int col[8] = {
6, 11, 10, 3, 17, 4, 8, 9
};

// 2-dimensional array of pixels:


int pixels[8][8];

int incomingByte = 0;

void setup() {
// initialize the I/O pins as outputs
// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
// initialize the output pins:
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);
// take the col pins (i.e. the cathodes) high to ensure that
// the LEDS are off:
digitalWrite(col[thisPin], HIGH);
}

clearScr();

Serial.begin(9600);

void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
doProcess(incomingByte);
}

// draw the screen:


refreshScreen();

const int SYNC_WORD = 0xFF;


const int ST_0_IDLE = 0;
const int ST_1_WAITX = 1;
const int ST_2_WAITY = 2;
const int ST_3_WAITB = 3;
int prc_State = ST_0_IDLE;
int dotX, dotY, dotB;

void doProcess(int b){


switch(prc_State){
case ST_0_IDLE:
if(b == SYNC_WORD){
prc_State = ST_1_WAITX;
Serial.println("1");
}
break;
case ST_1_WAITX:
dotX = b;
prc_State = ST_2_WAITY;
Serial.println("2");
break;
case ST_2_WAITY:
dotY = b;
prc_State = ST_3_WAITB;
Serial.println("3");
break;
case ST_3_WAITB:

if(b == 1){
pixels[dotY][dotX] = LOW;
}else{
pixels[dotY][dotX] = HIGH;
}

prc_State = ST_0_IDLE;
Serial.println("0");
break;
default:
prc_State = ST_0_IDLE;
}
}

void clearScr(){
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = HIGH;
}
}
}

void refreshScreen() {
// iterate over the rows (anodes):
for (int thisRow = 0; thisRow < 8; thisRow++) {
// take the row pin (anode) high:
digitalWrite(row[thisRow], HIGH);
// iterate over the cols (cathodes):
for (int thisCol = 0; thisCol < 8; thisCol++) {
// get the state of the current pixel;
int thisPixel = pixels[thisRow][thisCol];
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(col[thisCol], thisPixel);
// turn the pixel off:
if (thisPixel == LOW) {
digitalWrite(col[thisCol], HIGH);
}
}
// take the row pin low to turn off the whole row:
digitalWrite(row[thisRow], LOW);
}
}

You might also like