luishenriique

arduiino

May 29th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  5. IPAddress server(192,168,1,10);
  6. IPAddress ip(192,168,1,5);
  7.  
  8. EthernetClient client;
  9.  
  10. int led = 9;
  11.  
  12. void conexao(){
  13.  if (Ethernet.begin(mac) == 0) {
  14.     Serial.println("Failed to configure Ethernet using DHCP");
  15.     Ethernet.begin(mac, ip);
  16.   }
  17.   Serial.println("connecting...");
  18.  
  19.   if (client.connect(server, 80)) {
  20.     Serial.println("connected");
  21.     client.println("GET /android/janela.txt");
  22.     Serial.println("Funcionando");
  23.   }else{
  24.     Serial.println("connection failed");
  25.   }
  26. }
  27.  
  28. void setup() {
  29.   pinMode(led, OUTPUT);
  30.   Serial.begin(9600);
  31.  
  32.   conexao();
  33. }
  34.  
  35. void loop(){  
  36.   while(client.connected()){
  37.     if (client.available()) {
  38.     char c = client.read();
  39.    
  40.       if(c == '0'){
  41.         digitalWrite(led, LOW);
  42.       }else if (c == '1'){
  43.         digitalWrite(led, HIGH);
  44.       }
  45.    
  46.       Serial.print(c);
  47.     }
  48.   }
  49.   client.stop();
  50.  
  51.   if (!client.connected()) {
  52.     Serial.println();
  53.     Serial.println("disconnecting.");
  54.     conexao();
  55.   }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment