А
Size: a a a
А
А
В
В
В
В
В
В

В
В
O
O
#include <SPI.h>
#include <Ethernet.h>
boolean newInfo = 0;
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
byte gateway[] = { 192, 168, 4, 1 };
byte subnet[] = { 255, 255, 255, 0 };
IPAddress ip(192,168,4,70);
EthernetServer server(80);
int a;
int count;
int operation;
void setup()
{
cli();
pinMode(8, OUTPUT);
digitalWrite(8,HIGH);
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
/*
* Настройка таймера по переполнению
*/
TCCR1A = 0; // установить TCCR1A регистр в 0
OCR1A = 15624; // установка регистра совпадения
TCCR1B |= (1 << WGM12); // включение в CTC режим
TIMSK1 = (1 << OCIE1A);//включить прерывание Timer1 overflow
TCCR1B |= (1 << CS12);
TCCR1B |= (0 << CS11);
TCCR1B |= (1 << CS10);
sei();
a = 0;
count = 0;
operation = 0;
}
ISR(TIMER1_COMPA_vect)
{
switch (a){
case 1:
count = 0;
break;
case 2:
count = count + 1;
break;
default:;
}
if(a == 1)blinker();
}
void blinker()
{
/*
digitalWrite(8, LOW);
delay(8000);
digitalWrite(8, HIGH);
delay(5000);
digitalWrite(8, LOW);
delay(8000);
digitalWrite(8, HIGH);
delay(10000);
digitalWrite(8, LOW);
delay(210000);
digitalWrite(8, HIGH);
*/
if(operation == 1){
digitalWrite(8, HIGH);
operation = 2;
a = 1;
}
if((operation == 2) && (count == 8)){
digitalWrite(8, LOW);
operation = 3;
count = 0;
}
if((operation == 3) && (count == 5)){
digitalWrite(8, HIGH);
operation = 4;
count = 0;
}
if((operation == 4) && (count == 8)){
digitalWrite(8, LOW);
operation = 5;
count = 0;
}
if((operation == 5) && (count == 10)){
digitalWrite(8, HIGH);
operation = 6;
count = 0;
}
if((operation == 6) && (count == 210)){
digitalWrite(8, LOW);
operation = 0;
a = 0;
}
}
void loop()
{
EthernetClient client = server.available();
if(client){
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if(newInfo && c == ' '){
newInfo = 0;
}
if(c == '$'){
newInfo = 1;
}
if((newInfo == 1) && (operation == 0)){
Serial.println(c);
if(c == '1'){
Serial.println("ON");
operation = 1;
blinker();
}
if(c == '2'){
Serial.println("OFF");
digitalWrite(8, LOW);
}
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 30");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("<title>Web Server</title>");
client.print("<H1>Web Server</H1>");
client.print("<a href=\"/$1\"><button>On</button></a>");
client.print("<a href=\"/$2\"><button>Off</button></a>");
client.println("<br />");
client.println("</html>");
break;
}
}
}
delay(1);
client.stop();
}
}
В
#include <SPI.h>
#include <Ethernet.h>
boolean newInfo = 0;
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
byte gateway[] = { 192, 168, 4, 1 };
byte subnet[] = { 255, 255, 255, 0 };
IPAddress ip(192,168,4,70);
EthernetServer server(80);
int a;
int count;
int operation;
void setup()
{
cli();
pinMode(8, OUTPUT);
digitalWrite(8,HIGH);
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
/*
* Настройка таймера по переполнению
*/
TCCR1A = 0; // установить TCCR1A регистр в 0
OCR1A = 15624; // установка регистра совпадения
TCCR1B |= (1 << WGM12); // включение в CTC режим
TIMSK1 = (1 << OCIE1A);//включить прерывание Timer1 overflow
TCCR1B |= (1 << CS12);
TCCR1B |= (0 << CS11);
TCCR1B |= (1 << CS10);
sei();
a = 0;
count = 0;
operation = 0;
}
ISR(TIMER1_COMPA_vect)
{
switch (a){
case 1:
count = 0;
break;
case 2:
count = count + 1;
break;
default:;
}
if(a == 1)blinker();
}
void blinker()
{
/*
digitalWrite(8, LOW);
delay(8000);
digitalWrite(8, HIGH);
delay(5000);
digitalWrite(8, LOW);
delay(8000);
digitalWrite(8, HIGH);
delay(10000);
digitalWrite(8, LOW);
delay(210000);
digitalWrite(8, HIGH);
*/
if(operation == 1){
digitalWrite(8, HIGH);
operation = 2;
a = 1;
}
if((operation == 2) && (count == 8)){
digitalWrite(8, LOW);
operation = 3;
count = 0;
}
if((operation == 3) && (count == 5)){
digitalWrite(8, HIGH);
operation = 4;
count = 0;
}
if((operation == 4) && (count == 8)){
digitalWrite(8, LOW);
operation = 5;
count = 0;
}
if((operation == 5) && (count == 10)){
digitalWrite(8, HIGH);
operation = 6;
count = 0;
}
if((operation == 6) && (count == 210)){
digitalWrite(8, LOW);
operation = 0;
a = 0;
}
}
void loop()
{
EthernetClient client = server.available();
if(client){
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if(newInfo && c == ' '){
newInfo = 0;
}
if(c == '$'){
newInfo = 1;
}
if((newInfo == 1) && (operation == 0)){
Serial.println(c);
if(c == '1'){
Serial.println("ON");
operation = 1;
blinker();
}
if(c == '2'){
Serial.println("OFF");
digitalWrite(8, LOW);
}
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 30");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("<title>Web Server</title>");
client.print("<H1>Web Server</H1>");
client.print("<a href=\"/$1\"><button>On</button></a>");
client.print("<a href=\"/$2\"><button>Off</button></a>");
client.println("<br />");
client.println("</html>");
break;
}
}
}
delay(1);
client.stop();
}
}

В
В
В
O
O
В
В