Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LCD.h>
- #include <LiquidCrystal_I2C.h>
- #include <SPI.h>
- #include <Ethernet.h>
- #include <ICMPPing.h>
- #include <Timer.h>
- #define I2C_ADDR 0x3F // Define I2C Address where the SainSmart LCD is
- #define BACKLIGHT_PIN 3
- #define En_pin 2
- #define Rw_pin 1
- #define Rs_pin 0
- #define D4_pin 4
- #define D5_pin 5
- #define D6_pin 6
- #define D7_pin 7
- byte mac[] = {you dun need to know this}; // mac address for ethernet shield (on the back of the shield)
- byte ip[] = {172, 16, 0, 16}; // ip address for ethernet shield
- byte pingAddr[6][4] = {{74, 125, 224, 198},
- {165, 254, 42, 40},
- {69, 53, 236, 17},
- {69, 13, 38, 151},
- {69, 13, 38, 153},
- {198, 12, 14, 165}}; // ip address to ping
- String pings[6];
- SOCKET pingSocket = 0;
- char buffer [256];
- ICMPPing ping(pingSocket);
- Timer t;
- LiquidCrystal_I2C lcd = LiquidCrystal_I2C(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
- int panel = 0;
- int panels = 2;
- boolean up_lastState;
- boolean up_state;
- boolean down_lastState;
- boolean down_state;
- String pingNames[] = {"Google", "Reddit", "Netflix",
- "CC Big 1", "CC Fish", "mc-sg.org"};
- String titles [] = {"Ping Test (Major)",
- "Ping Test (Games)"};
- void setup()
- {
- Serial.begin(9600);
- pinMode(6, INPUT);
- pinMode(7, INPUT);
- pinMode(8, OUTPUT);
- Ethernet.begin(mac, ip);
- lcd.begin (20, 4);
- // Switch on the backlight
- lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
- lcd.setBacklight(HIGH);
- // Position cursor and write some text
- updateLCD();
- t.every(6000, updateLCD);
- }
- void loop()
- {
- checkButtons();
- t.update();
- }
- void updateLCD()
- {
- for (int j = 0; j < 3; j++)
- {
- pings[panel * 3 + j] = getPing(panel * 3 + j);
- }
- lcd.clear();
- lcd.home();
- lcd.print(titles[panel]);
- lcd.setCursor(18, 0);
- lcd.print("|");
- for (int i = 0; i < 3; i++)
- {
- if (pingNames[i].length() < 10)
- {
- lcd.setCursor(0, i + 1);
- lcd.print(pingNames[panel * 3 + i]);
- lcd.setCursor(9, i + 1);
- lcd.print("|");
- Serial.println(pings[panel*3+i]);
- if (pings[panel * 3 + i] == "TimedOut")
- {
- lcd.setCursor(10, i + 1);
- lcd.print("TimedOut");
- }
- else
- {
- lcd.setCursor(11, i + 1);
- lcd.print(pings[panel * 3 + i]);
- }
- lcd.setCursor(18, i + 1);
- lcd.print("|");
- }
- else
- {
- Serial.println("ERROR: Server names need to be <10 characters");
- }
- }
- }
- String getPing(int siteNum)
- {
- ping(2 , pingAddr[siteNum], buffer);
- String sBuffer = String(buffer);
- if (sBuffer == "Request Timed Out")
- {
- return "TimedOut";
- }
- sBuffer = sBuffer.substring(sBuffer.indexOf("time=") + 5, sBuffer.indexOf("ms") + 2);
- return sBuffer;
- }
- void checkButtons()
- {
- // Up Button
- up_state = digitalRead(6);
- if (up_state != up_lastState)
- {
- delay(50); // bounce protection
- up_state = digitalRead(6);
- if (up_state == HIGH)
- {
- if (panel > 0)
- {
- panel--;
- updateLCD();
- tone(8, 450, 75);
- delay(75);
- tone(8, 550, 75);
- }
- }
- }
- up_lastState = up_state;
- // Down Button
- down_state = digitalRead(7);
- if (down_state != down_lastState)
- {
- delay(50); // bounce protection
- down_state = digitalRead(7);
- if (down_state == HIGH)
- {
- if (panel < panels - 1)
- {
- panel++;
- updateLCD();
- tone(8, 850, 75);
- delay(75);
- tone(8, 950, 75);
- }
- }
- }
- down_lastState = down_state;
- }
Advertisement
Add Comment
Please, Sign In to add comment