Advertisement
Guest User

Untitled

a guest
Apr 6th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <Udp.h>
  4. #include <EthernetUdp.h>
  5.  
  6.  
  7.  
  8. // Communications
  9. EthernetUDP Udp; // To send & receive packets using UDP
  10.  
  11.  
  12. /**********************************************************
  13. CETS bir grup mac adresine statik IP atadı.
  14. Bu mac adreslerini kullanarak DHCP kullanırsanız,
  15. Statik IP atanır. Aksi takdirde,
  16. Kendi mac add ve IP adresini bir cihaza yüklemek zorunda kalırsa
  17. Airpenn net'in güvenlik sayfasına gidin.
  18. Bu mac ve statik adresler,
  19. Mühendislikbinası
  20.  
  21. .***********************************************************/
  22.  
  23. // MAC ve IP dizilimindeki "**" değerini atanmış rakamlarla değiştirin
  24. byte mac[] = {0x2A, 0x00, 0x00, 0x00, 0x00, 0x00};
  25. byte ip[] = {192, 168, 1, 50};
  26. byte remoteIp[4] = {192, 168, 1, 51}; // Receiver unit’s IP address
  27.  
  28. // -------- Aşağıdaki bölümü değiştirmeyin -----------------
  29. char UDPMessageBuffer[80];
  30. const unsigned int localPort = 9631;
  31. unsigned int remotePort = 1369;
  32. // ----------------------------------------------------------
  33.  
  34.  
  35. // Sıcaklık sensorune bağlı pini yıldızların olduğu yere yazın
  36.  
  37. int analogPin = 05;
  38.  
  39. void setup()
  40. {
  41. Ethernet.begin(mac, ip); // Set up the Ethernet Shield
  42. Udp.begin(localPort); // Open a socket for this port
  43. Serial.begin(9600); // Set up serial monitor with PC
  44. }
  45.  
  46. void loop()
  47. {
  48. /****************************************************
  49. Print out the values from the temperature sensor onto
  50. the serial monitor in degrees Fahrenheit. Math required
  51. to convert the value to temperature in F. You should
  52. have figured this out for your pre-lab.
  53. ****************************************************/
  54.  
  55. float val = analogRead(analogPin);
  56.  
  57. int degreeF = val -10 +10; // Replace *s with some math(+, -, *, /)
  58.  
  59. Serial.println(degreeF); // Show value on serial monitor
  60.  
  61.  
  62.  
  63.  
  64. // Alıcı Arduino ya sıcaklık değerlerini gönder
  65.  
  66. itoa(degreeF, UDPMessageBuffer, 10);
  67. Udp.sendPacket(UDPMessageBuffer, remoteIp, remotePort);
  68. strcpy(UDPMessageBuffer, ""); // Clear the message
  69.  
  70. // Delay for 200ms so temperature is updated once every 200ms
  71. delay(200);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement