Передача данных по thernet shield между двумя Iteaduino UNO
- Войдите на сайт для отправки комментариев
Втр, 18/02/2014 - 06:34
Народ добрый день, подскажите пример кода: 2 Iteaduino UNO с интернет шилдами между собой соеденены кабелем, к примеру на одной стороне датчик огня, по срабатыванию датчика на втором загорается диод
Ардуино + Visual C# - передача данных по Ethernet шилд, управлять и получать данные
... на одной стороне датчик огня, по срабатыванию датчика на втором загорается диод
если огонь достаточно сильный, то загорится само, даже без проводов
Типо пошутили да
Ладно это не подскажите, так хоть подскажите что не так в коде
Пытаюсь управлять двумя светодиодами но чтоб по отдельности, одновременно два не хотят гореть да и вообще чтото не так
#include <SPI.h> #include <Ethernet.h> // MAC address from Ethernet shield sticker under board byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(10, 0, 0, 20); // IP address, may need to change depending on network EthernetServer server(80); // create a server at port 80 String HTTP_req; // stores the HTTP request boolean LED_status = 0; // статус светодиода выключен boolean LED_status2 = 0; // статус светодиода выключен void setup() { Ethernet.begin(mac, ip); // initialize Ethernet device server.begin(); // start to listen for clients Serial.begin(9600); // скорость передачи БОД pinMode(3, OUTPUT); // Порт pin 3 pinMode(7, OUTPUT); // Порт pin 7 } void loop() { EthernetClient client = server.available(); // try to get client if (client) { // got client? boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { // client data available to read char c = client.read(); // read 1 byte (character) from client HTTP_req += c; // save the HTTP request 1 char at a time // last line of client request is blank and ends with \n // respond to client only after last line received if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println(); // send web page client.println("<!DOCTYPE html>"); client.println("<html>"); client.println("<head>"); client.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> "); client.println("<title>Arduino Управление ДПРМ</title>"); client.println("</head>"); client.println("<body>"); client.println("<h1>Управление сведодиодом</h1>"); client.println("<p>Чекбокс нажат - светодиод горит/Чекбок отжат - светодиод не горит.</p>"); client.println("<form method=\"get\">"); ProcessCheckbox(client); ProcessCheckbox2(client); client.println("</form>"); client.println("</body>"); client.println("</html>"); client.println("<hr />"); client.println("</body></html>"); //черта Serial.print(HTTP_req); HTTP_req = ""; // finished with request, empty string break; } // every line of text received from the client ends with \r\n if (c == '\n') { // last character on line of received text // starting new line with next character read currentLineIsBlank = true; } else if (c != '\r') { // a text character was received from client currentLineIsBlank = false; } } // end if (client.available()) } // end while (client.connected()) delay(1); // give the web browser time to receive the data client.stop(); // close the connection } // end if (client) } // switch LED and send back HTML for LED checkbox void ProcessCheckbox(EthernetClient cl) { if (HTTP_req.indexOf("LED2=2") > -1) { // see if checkbox was clicked // the checkbox was clicked, toggle the LED if (LED_status) { LED_status = 0; } else { LED_status = 1; } } if (LED_status) { // сведодиод включен digitalWrite(3, HIGH); // Чекбокс нажат cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \ onclick=\"submit();\" checked>LED2"); } else { // светодиод выключен digitalWrite(3, LOW); // Чекбокс отжат cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \ onclick=\"submit();\">LED2"); } } void ProcessCheckbox2(EthernetClient cl2) { if (HTTP_req.indexOf("LED3=3") > -1) { // see if checkbox was clicked // the checkbox was clicked, toggle the LED if (LED_status2) { LED_status2 = 0; } else { LED_status2 = 1; } } if (LED_status2) { // сведодиод включен digitalWrite(7, HIGH); // Чекбокс нажат cl2.println("<input type=\"checkbox\" name=\"LED3\" value=\"3\" \ onclick=\"submit();\" checked>LED3"); } else { // светодиод выключен digitalWrite(7, LOW); // Чекбокс отжат cl2.println("<input type=\"checkbox\" name=\"LED3\" value=\"3\" \ onclick=\"submit();\">LED3"); } }Классный IP-адрес. Что ж у вас там за сеть-то такая? )))
Нету никакой сети, просто подсоеденил ардуино к сетевой плате, пытаюсь по отдельности включать светодиоды (по примеру) по отдельности светятся, а вместе не хотят, один вырубается
Подскажите пожалуйста, программная подтяжка на вход к + , правильно?
byte ip[] = { 192, 168, 0, 2 }; // IP адрес
EthernetServer server(80);
int numPins = 8;
int pins[] = { 2, 3, 4, 5, 6, 7, 8, 9 }; // Пины для реле
int pinState[] = { 1, 1, 1, 1, 1, 1, 1, 1 }; // Состояние пинов
void setup()
{
// Изначально выключаем все реле
for (int i = 0; i < numPins; i++)
{
pinMode(pins[i], INPUT_PULLUP);
digitalWrite(pins[i], 1);
}
Удалите тему, все равно никто не помог