#include "etherShield.h" static uint8_t mymac[6] = {0x00,0x80,0x48,0x2d,0xf7,0x25}; // mac- static uint8_t myip[4] = {10,20,30,40}; // ip- 10.20.30.40 #define MYPORT 5555 #define BUFFER_SIZE 500 static uint8_t buf[BUFFER_SIZE+1]; static char number[7]; const byte clockPin = 7; // const byte latchPin = 8; // const byte dataPin = 9; // const byte NumRegs = 4; // const byte NumCols=10; const byte NumRows=16; // - , // // 4 , , // // () 1 32 // 26 (10+16) - byte Col_bits[NumCols] = {3,5,7,11,13,15,19,21,23,27}; // // , .. 1- // 3 .. byte Row_bits[NumRows] = {32,30,28,26,24,22,20,18,16,14,12,10,8,6,4,2}; // // byte Regs[NumRegs]; int reg_n, bit_n, in_r, in_c; // , . // 2! ;) // - byte matrix[NumRows][NumCols]={{1,0,1,0,0,0,1,1,1,1}, {1,0,1,0,0,0,0,0,0,1}, {1,0,1,0,0,0,0,0,0,1}, {1,0,1,0,0,0,0,0,1,0}, {1,0,1,0,0,0,0,0,1,0}, {1,0,1,1,0,0,0,0,1,0}, {1,0,1,0,1,0,0,1,0,0}, {1,0,1,0,1,0,0,1,0,0}, {1,0,1,0,1,0,0,1,0,0}, {1,0,1,0,1,0,1,0,0,0}, {1,0,1,0,1,0,1,0,0,0}, {1,0,1,1,0,0,1,1,1,1}, {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}}; EtherShield es=EtherShield(); void setup() { pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); es.ES_enc28j60Init(mymac); // es.ES_init_ip_arp_udp_tcp(mymac,myip, MYPORT); // } void loop() { uint16_t plen, dat_p, ptr; while(1) { burn_matrix(); // // ( ). // , // - // - read packet, handle ping and wait for a tcp packet: dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf)); /* dat_p will be unequal to zero if there is a valid request */ if(dat_p == 0) { // no request continue; } // :) // "IbZ " if (strncmp("IbZ ",(char *)&(buf[dat_p]),4)==0) { // 4- ptr = dat_p+4; for(in_r=0; in_r < NumRows; in_r++) { for(in_c=0; in_c < NumCols; in_c++) { matrix[in_r][in_c] = 0; // ( , ;) ) } } // - - // , - 0 while(buf[ptr] != 0) { in_r = (buf[ptr]-1) % 16; in_c = (buf[ptr]-1) / 16; matrix[in_r][in_c] = 1; // ptr++; } } } } void burn_matrix() { // - 1- , , // 2- , 10- for(int c = 0; c < NumCols; c++) { for(int i = 0; i < NumRegs; i++) { Regs[i]=255; } reg_n = (Col_bits[c]-1) / 8; bit_n = (Col_bits[c]-1) % 8; bitWrite(Regs[reg_n], bit_n, 0); for(int r = 0; r < NumRows; r++) { reg_n = (Row_bits[r]-1) / 8; bit_n = (Row_bits[r]-1) % 8; bitWrite(Regs[reg_n], bit_n, matrix[r][c]); } registerWrite(); delay(1); } } // - void registerWrite() { digitalWrite(latchPin, LOW); for(int cur_reg = NumRegs-1; cur_reg >= 0; cur_reg-- ) { shiftOut(dataPin, clockPin, MSBFIRST, Regs[cur_reg]); } digitalWrite(latchPin, HIGH); }
#include "etherShield.h" static uint8_t mymac[6] = {0x00,0x80,0x48,0x2d,0xf7,0x25}; // mac- static uint8_t myip[4] = {10,20,30,40}; // ip- 10.20.30.40 #define MYPORT 5555 #define BUFFER_SIZE 500 static uint8_t buf[BUFFER_SIZE+1]; static char number[7]; const byte clockPin = 7; // const byte latchPin = 8; // const byte dataPin = 9; // const byte NumRegs = 4; // const byte NumCols=10; const byte NumRows=16; // - , // // 4 , , // // () 1 32 // 26 (10+16) - byte Col_bits[NumCols] = {3,5,7,11,13,15,19,21,23,27}; // // , .. 1- // 3 .. byte Row_bits[NumRows] = {32,30,28,26,24,22,20,18,16,14,12,10,8,6,4,2}; // // byte Regs[NumRegs]; int reg_n, bit_n, in_r, in_c; // , . // 2! ;) // - byte matrix[NumRows][NumCols]={{1,0,1,0,0,0,1,1,1,1}, {1,0,1,0,0,0,0,0,0,1}, {1,0,1,0,0,0,0,0,0,1}, {1,0,1,0,0,0,0,0,1,0}, {1,0,1,0,0,0,0,0,1,0}, {1,0,1,1,0,0,0,0,1,0}, {1,0,1,0,1,0,0,1,0,0}, {1,0,1,0,1,0,0,1,0,0}, {1,0,1,0,1,0,0,1,0,0}, {1,0,1,0,1,0,1,0,0,0}, {1,0,1,0,1,0,1,0,0,0}, {1,0,1,1,0,0,1,1,1,1}, {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}}; EtherShield es=EtherShield(); void setup() { pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); es.ES_enc28j60Init(mymac); // es.ES_init_ip_arp_udp_tcp(mymac,myip, MYPORT); // } void loop() { uint16_t plen, dat_p, ptr; while(1) { burn_matrix(); // // ( ). // , // - // - read packet, handle ping and wait for a tcp packet: dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf)); /* dat_p will be unequal to zero if there is a valid request */ if(dat_p == 0) { // no request continue; } // :) // "IbZ " if (strncmp("IbZ ",(char *)&(buf[dat_p]),4)==0) { // 4- ptr = dat_p+4; for(in_r=0; in_r < NumRows; in_r++) { for(in_c=0; in_c < NumCols; in_c++) { matrix[in_r][in_c] = 0; // ( , ;) ) } } // - - // , - 0 while(buf[ptr] != 0) { in_r = (buf[ptr]-1) % 16; in_c = (buf[ptr]-1) / 16; matrix[in_r][in_c] = 1; // ptr++; } } } } void burn_matrix() { // - 1- , , // 2- , 10- for(int c = 0; c < NumCols; c++) { for(int i = 0; i < NumRegs; i++) { Regs[i]=255; } reg_n = (Col_bits[c]-1) / 8; bit_n = (Col_bits[c]-1) % 8; bitWrite(Regs[reg_n], bit_n, 0); for(int r = 0; r < NumRows; r++) { reg_n = (Row_bits[r]-1) / 8; bit_n = (Row_bits[r]-1) % 8; bitWrite(Regs[reg_n], bit_n, matrix[r][c]); } registerWrite(); delay(1); } } // - void registerWrite() { digitalWrite(latchPin, LOW); for(int cur_reg = NumRegs-1; cur_reg >= 0; cur_reg-- ) { shiftOut(dataPin, clockPin, MSBFIRST, Regs[cur_reg]); } digitalWrite(latchPin, HIGH); }
Breadboard Prototype PCB Print Circuit Board 18 x 30 | ~ $ 4 |
160 3mm green LEDs | less than $ 5 can be found |
Arduino | ~ $ 16 |
ENC28J60 Ethernet Shield for Arduino Duemilanove / Uno | ~ $ 16 |
4 registers 74HC595 | ~ $ 3 |
Total | ~ $ 45-50 |
Source: https://habr.com/ru/post/142245/
All Articles