Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SD.h>
- #include <SPI.h>
- #include <Ethernet.h>
- int i = 0;
- int j = 0; // array pointer:
- char chtr; // variable to hold value from file:
- char name[4]; // array for name data:
- char value[8];
- byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
- byte ip[] = {10, 0, 0, 59};
- // set up variables using the SD utility library functions:
- Sd2Card card;
- int SD_CS = 4;
- void setup() {
- Serial.begin(9600);
- // disable w5100 SPI while setting up SD
- digitalWrite(10,HIGH); // Disabled
- Serial.print("Starting SD...");
- pinMode(10,OUTPUT);
- if(!SD.begin(4)) Serial.println("SD failed to start");
- else Serial.println("ok");
- // SD.begin() returns with its SPI disabled. Good SD library!
- if (!card.init(SPI_HALF_SPEED, SD_CS)) {
- Serial.println("Initialization Failed.");
- } else {
- Serial.println("Wiring is correct and a card is present.");
- }
- delay (2000);
- Serial.print("Starting w5100...");
- Serial.println();
- readFile();
- Ethernet.begin(mac, ip);
- Serial.println();
- Serial.print("Arduino set IP to ");
- Serial.println();
- Serial.println(Ethernet.localIP());
- // rest of your setup
- }
- void loop(){}
- void readFile() {
- File file;
- file=SD.open("params.txt");
- if (file) {
- // array for value data:
- while (file.available()) { // read the settings file:
- i = 0;
- boolean paramEnd = false;
- while (!paramEnd) { // while not at the end of the parameter keep reading:
- chtr = file.read();
- if (chtr != ':') { // if the char from file is not a':' read it in:
- name[i] = chtr;
- i++;
- } else {
- paramEnd = true; // otherwise we have come to the end of our parmeter name:
- }
- }
- j = 0;
- boolean valueEnd = false;
- value[0] = '\0'; // reset our array pointer:
- while (!valueEnd) {
- chtr = file.read();
- if (chtr != ',') { // if the char from file is not a ',' read it in:
- value[j] = chtr;
- j++;
- } else {
- valueEnd = true; // otherwise we have come to the end of our value:
- }
- }
- if (!strcmp(name, "ip0")) {
- ip[0] = atoi(value); // assign value to ip0 first ip octet:
- }
- if (!strcmp(name, "ip1")) {
- ip[1] = atoi(value); // assign value to ip1 first ip octet:
- }
- if (!strcmp(name, "ip2")) {
- ip[2] = atoi(value); // assign value to ip2 first ip octet:
- }
- if (!strcmp(name, "ip3")) {
- ip[3] = atoi(value); // assign value to ip4 first ip octet:
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement