Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include <Udp.h>
- #include <LiquidCrystal.h>
- #include <EthernetUdp.h>
- // Communications
- EthernetUDP Udp; // To send & receive packets using UDP
- /**********************************************************
- CETS bir grup mac adresine statik IP atadı.
- Bu mac adreslerini kullanarak DHCP kullanırsanız,
- Statik IP atanır. Aksi takdirde,
- Kendi mac add ve IP adresini bir cihaza yüklemek zorunda kalırsa
- Airpenn net'in güvenlik sayfasına gidin.
- Bu mac ve statik adresler,
- Mühendislik binası.
- ***********************************************************/
- // Replace "**" in the mac and ip array with assigned digits
- byte mac[] = { 0x2A, 0x00, 0x01, 0x01, 0x01, 0x01 };
- byte ip[] = {192, 168, 1, 51};
- // -------- Do not change the section below -----------------
- const unsigned int localPort = 1369; // Process ID port
- char recvdBuffer[UDP_TX_PACKET_MAX_SIZE+1]; // Buffer for incoming data
- byte remoteIp[4]; // Holds source IP address from incoming data
- unsigned int remotePort; // Holds source port # from incoming data
- LiquidCrystal lcd(8, 6, 7, 5, 3, 4); // Set up LCD screen on open pins
- // ------------------------------------------------------------
- // Pin for the buzzer. Pin 9 is the easiest available pin.
- const int buzzerPin = 9;
- // Sets the threshold temperature in Fahrenheit for the buzzer
- int alarmThreshold = 85;
- void setup()
- {
- lcd.begin(16, 2); // Set up LCD, only done once in beginning
- Ethernet.begin(mac,ip); // Set up the Ethernet Shield
- Udp.begin(localPort); // Open a socket for this port
- Serial.begin(9600); // Set up serial monitor with PC
- pinMode(buzzerPin, OUTPUT); // Set buzzer pin to output
- /**********************************************************
- The following code will print a test on the LCD. It will
- print out "Hi" on the first line, move to the second line,
- and then print "there" so the screen reads "Hi there." See
- how it is done below to use for displaying temperature later.
- ***********************************************************/
- lcd.clear(); // Always clear the lcd before writing a frame
- lcd.print("Hi"); // Print "Hi" for testing
- lcd.setCursor(0, 1); // Move cursor to beginning of next line
- lcd.print("there"); // Print "there" for testing
- // Delay to see text on screen before it's cleared and overwritten
- delay(500);
- }
- void loop()
- {
- int recvdSize = Udp.available();
- if(recvdSize) {
- Udp.readPacket(recvdBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp,
- remotePort);
- recvdBuffer[recvdSize] = '\0';
- recvdSize -= 8; // Gets rid of the message header
- Serial.println(recvdBuffer); // Prints received data to serial
- /*******************************************************
- Print out the temperature and alarmThreshold on the lcd
- screen. Hint: Refer to setup() above to see LCD writing
- commands. The temperature value is stored in the variable
- called temperature.
- *******************************************************/
- int temperature = atoi(recvdBuffer);
- /*******************************************************
- Activate buzzer alarm when temperature threshold is
- exceeded using if else statements.
- *******************************************************/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement