Advertisement
Guest User

Untitled

a guest
Apr 6th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <Udp.h>
  4. #include <LiquidCrystal.h>
  5. #include <EthernetUdp.h>
  6.  
  7.  
  8.  
  9. // Communications
  10. EthernetUDP Udp; // To send & receive packets using UDP
  11.  
  12.  
  13. /**********************************************************
  14. CETS bir grup mac adresine statik IP atadı.
  15. Bu mac adreslerini kullanarak DHCP kullanırsanız,
  16. Statik IP atanır. Aksi takdirde,
  17. Kendi mac add ve IP adresini bir cihaza yüklemek zorunda kalırsa
  18. Airpenn net'in güvenlik sayfasına gidin.
  19. Bu mac ve statik adresler,
  20. Mühendislik binası.
  21. ***********************************************************/
  22.  
  23. // Replace "**" in the mac and ip array with assigned digits
  24. byte mac[] = { 0x2A, 0x00, 0x01, 0x01, 0x01, 0x01 };
  25. byte ip[] = {192, 168, 1, 51};
  26.  
  27. // -------- Do not change the section below -----------------
  28. const unsigned int localPort = 1369; // Process ID port
  29. char recvdBuffer[UDP_TX_PACKET_MAX_SIZE+1]; // Buffer for incoming data
  30. byte remoteIp[4]; // Holds source IP address from incoming data
  31. unsigned int remotePort; // Holds source port # from incoming data
  32. LiquidCrystal lcd(8, 6, 7, 5, 3, 4); // Set up LCD screen on open pins
  33. // ------------------------------------------------------------
  34.  
  35. // Pin for the buzzer. Pin 9 is the easiest available pin.
  36. const int buzzerPin = 9;
  37.  
  38. // Sets the threshold temperature in Fahrenheit for the buzzer
  39. int alarmThreshold = 85;
  40.  
  41.  
  42. void setup()
  43. {
  44. lcd.begin(16, 2); // Set up LCD, only done once in beginning
  45. Ethernet.begin(mac,ip); // Set up the Ethernet Shield
  46. Udp.begin(localPort); // Open a socket for this port
  47. Serial.begin(9600); // Set up serial monitor with PC
  48. pinMode(buzzerPin, OUTPUT); // Set buzzer pin to output
  49.  
  50.  
  51. /**********************************************************
  52. The following code will print a test on the LCD. It will
  53. print out "Hi" on the first line, move to the second line,
  54. and then print "there" so the screen reads "Hi there." See
  55. how it is done below to use for displaying temperature later.
  56. ***********************************************************/
  57.  
  58. lcd.clear(); // Always clear the lcd before writing a frame
  59. lcd.print("Hi"); // Print "Hi" for testing
  60. lcd.setCursor(0, 1); // Move cursor to beginning of next line
  61. lcd.print("there"); // Print "there" for testing
  62.  
  63.  
  64. // Delay to see text on screen before it's cleared and overwritten
  65. delay(500);
  66. }
  67.  
  68. void loop()
  69. {
  70. int recvdSize = Udp.available();
  71. if(recvdSize) {
  72. Udp.readPacket(recvdBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp,
  73. remotePort);
  74.  
  75. recvdBuffer[recvdSize] = '\0';
  76. recvdSize -= 8; // Gets rid of the message header
  77. Serial.println(recvdBuffer); // Prints received data to serial
  78.  
  79.  
  80. /*******************************************************
  81. Print out the temperature and alarmThreshold on the lcd
  82. screen. Hint: Refer to setup() above to see LCD writing
  83. commands. The temperature value is stored in the variable
  84. called temperature.
  85. *******************************************************/
  86. int temperature = atoi(recvdBuffer);
  87.  
  88.  
  89.  
  90.  
  91. /*******************************************************
  92. Activate buzzer alarm when temperature threshold is
  93. exceeded using if else statements.
  94. *******************************************************/
  95.  
  96.  
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement