Интерактивный курс по ардуино на базе простого стартового набора

// Show messages scrolling from right to left.
#include

#define SPACE { \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0} \
}

#define E { \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}

#define G { \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 1, 1, 1}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}

#define H { \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0} \
}

#define K { \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 1, 0, 0, 0}, \
{0, 1, 1, 1, 0, 0, 0, 0}, \
{0, 1, 0, 1, 0, 0, 0, 0}, \
{0, 1, 0, 0, 1, 0, 0, 0}, \
{0, 1, 0, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0} \
}

#define L { \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}

#define O { \
{0, 0, 0, 1, 1, 0, 0, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 0, 0, 1, 1, 0, 0, 0} \
}

byte col=0;
byte leds[8][8];

int pins[17]={-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};
int cols[8] ={pins[13], pins[3], pins[4], pins[10], pins[06], pins[11], pins[15], pins[16]};
int rows[8] ={pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};

const int numPatterns=10;
byte patterns[numPatterns][8][8]={H, E, L, L, O, SPACE, G, K, L, SPACE};
int pattern=0;

void setup ()
{
for (int i=1; i<=16; i++) {pinMode(pins[i], OUTPUT);}
for (int i=1; i<=8; i++) {digitalWrite(cols[i-1], LOW);}
for (int i=1; i<=8; i++) {digitalWrite(rows[i-1], LOW);}

clearLeds ();

FrequencyTimer2:: disable ();
FrequencyTimer2:: setPeriod (2000); // sets refresh rate
FrequencyTimer2:: setOnOverflow (display);
setPattern (pattern);
}

void loop ()
{
pattern=++pattern%numPatterns;
slidePattern (pattern, 60);
}

void clearLeds () {
for (int i=0; i<8; i++) {
for (int j=0; j<8; j++) {leds[i][j]=0;}
}
}

void setPattern (int pattern) {
for (int i=0; i<8; i++) {
for (int j=0; j<8; j++) {leds[i][j] = patterns[pattern][i][j];}
}
}

void slidePattern (int pattern, int del) {
for (int l=0; l<8; l++) {
for (int i=0; i<7; i++) {
for (int j=0; j<8; j++) {leds[j][i] = leds[j][i+1];}
}
for (int j=0; j<8; j++) {leds[j][7] = patterns[pattern][j][0 + l];}
delay (del);
}
}

void display () {
digitalWrite (cols[col], LOW);
col++;
if (col==8) {col=0;}
for (int row=0; row<8; row++) {
if (leds[col][7-row]==1) {digitalWrite (rows[row], LOW);}
else {digitalWrite (rows[row], HIGH);}
}
digitalWrite (cols[col], HIGH);}

© Geektimes