Skip to content

Instantly share code, notes, and snippets.

@ssaluk
Created May 13, 2017 15:46
Show Gist options
  • Save ssaluk/5b4289a229399a07478fc57f32060074 to your computer and use it in GitHub Desktop.
Save ssaluk/5b4289a229399a07478fc57f32060074 to your computer and use it in GitHub Desktop.
Arduino 1388ASR
/*Warning: the next three program lines (the definition of three array) may seem complicated, but are a brilliant system (found on the net) to simplify management of array. For this reason definitely worth it to spend a few minutes to analyze them, interpret comments ,and understand how they works. *
The "pins" array defines the correlation between the matrix legs (represented by
the index used to scroll the table) and arduino's pins: the pins 2 to 17 (considering how pins 14,15, 16 and 17 the analog pins A0, A1, A2, and A3).
The first item in the table ("99") is present only in order to occupy a place and allow the index to start from the value of 1.
Reading the table shows that the leg 1 is connected to pin 5, leg 2 to pin 4, leg 3 at pin 3...
*/
int pins[17]= { 99, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};
/*The "cols" array defines the correlation between the columns (1 to 8) and the Arduino pins.
* Considering the previous "pins" array you can deduct that the first column is connected
* to the pins defined by pins [13] and that means the thirteenth element of the pins array
* (considering the first as zero element), and then the pin 9. The second column,
* is connected to the pin defined by pins [10], the tenth item of the pins array, wich value is 12...
*/
int cols[8] = { pins[13], pins[10], pins[15], pins[9], pins[4], pins[16], pins[6], pins[1]};
/*
the "rows" array defines the correlation between the lines (1 to 8) and the pins to which they are connected.
As already seen for columns, it follows that the first line is connected to the pin defined by "pins [8]"
and that means the pin 17 (A4); the second row is connected to "pins [7]" and that means the pin 16 (A3)...
*/
int rows[8] = {pins[8], pins[7], pins[3], pins[14], pins[2], pins[12], pins[11], pins[5]};
//
//
int buttonPin = 1;
int picture_happy[8][8] = {
{1, 1, 1, 0, 0, 1, 1, 1},
{1, 0, 1, 0, 0, 1, 0, 1},
{1, 1, 1, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 1},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 0, 1, 1, 1, 1, 0, 0}
};
int picture_sad[8][8] = {
{0, 1, 0, 0, 0, 0, 1, 0},
{1, 1, 1, 0, 0, 1, 1, 1},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 1, 0, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{1, 0, 0, 0, 0, 0, 0, 1}
};
void setup()
{
pinMode(buttonPin, INPUT); // button pin input mode
for (int i = 1; i <= 16; i++) // definisce come output tutte le porte definite nella tabella pins)
{
pinMode(pins[i], OUTPUT);
}
for (int i = 1; i <= 8; i++)
{
// definisce low tutti i pin e pertanto spegne tutti i led
// Arduino: matrice led 8x8 – 8x8 led matrix 8x8 – first step
for (int i = 1; i <= 16; i++) // definisce come output tutte le porte definite nella tabella pins)
digitalWrite(cols[i - 1], HIGH);
digitalWrite(rows[i - 1], LOW);
}
}
void loop()
{
int buttonState = digitalRead(buttonPin);
bool sad = buttonState == LOW;
for (int row = 0; row < 8; ++row)
{
//bool emptyRow = true;
digitalWrite(rows[row], HIGH);
for (int column = 0; column < 8; ++column)
{
int columnValue = sad ? picture_sad[row][column] : picture_happy[row][column];
digitalWrite(cols[column], columnValue > 0 ? LOW : HIGH);
//delay(0.5);
//digitalWrite(cols[column], HIGH);
if (columnValue > 0) {
digitalWrite(cols[column], HIGH);
}
}
digitalWrite(rows[row], LOW);
}
}
/*
void loop()
{
for (int i = 1; i <= 8; i++)
{
digitalWrite(rows[i - 1], HIGH); // accende progressivamente tutti i led di ogni riga
//digitalWrite(cols[0], LOW);
delay(100);
}
for (int i = 1; i <= 8; i++)
{
digitalWrite(rows[i - 1], LOW); // spegne progressivamente tutti i led di ogni riga
//digitalWrite(cols[0], HIGH);
delay(100);
}
}*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment