-
Notifications
You must be signed in to change notification settings - Fork 3
Parte tres
gism edited this page Feb 1, 2015
·
1 revision
void setup() {
// initialize the I/O pins as outputs
//initialize columns
pinMode(6, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(3, OUTPUT);
pinMode(17, OUTPUT);
pinMode(4, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
//initialize rows
pinMode(2, OUTPUT);
pinMode(7, OUTPUT);
pinMode(19, OUTPUT);
pinMode(5, OUTPUT);
pinMode(13, OUTPUT);
pinMode(18, OUTPUT);
pinMode(12, OUTPUT);
pinMode(16, OUTPUT);
// initialize the pixel matrix:
initializePixels();
//digitalWrite(row[thisRow], LOW);
//encendemos el led a la posicion 2x2
digitalWrite(7, HIGH);
digitalWrite(11, LOW);
//Encendemos el LED a la posición 4x4
digitalWrite(5, HIGH);
digitalWrite(3, LOW);
}
void loop() {
}
void initializePixels(){
// 2-dimensional array of row pin numbers:
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];
// initialize the pixel matrix:
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = HIGH;
}
}
refreshScreen();
}
// 2-dimensional array of row pin numbers:
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 };
int pixels[8][8];
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);
}
}