ethernet and timer library together

Hi,

i’ve two written two pieces of code. A piece of code to insert data to a sql database, another piece with a timer. The timer code does this; When i push on one button the led will go on for a presseted amount of time. if i press the another button the led will turn of immediately. What i want is when the timer goes off, the time that the led was on will be inserted to a database. later if i got this code right i want to control the time from a webpage but this is not for now. now my problem is the two pieces of code work fine apart, when i try to combine the code togherther my led doenst work anymore. can someone help me? Thanks in advance

code to insert to sql database

#include <Ethernet.h> // Used for Ethernet

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                       
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server[] = "192.168.0.199"; // IP Adres (or name) of server to dump data 
int  interval = 5000; // Wait between dumps

void setup() {

  Serial.begin(9600);
  Ethernet.begin(mac);

  Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
  Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  Serial.print("IP Address        : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP     : ");
  Serial.println(Ethernet.dnsServerIP());
}

void loop() {
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( "GET /add_data.php?");
    client.print("serial=");
    client.print( "02:00:00" );
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(server);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }
  else {
    // you didn't get a connection to the server:
    Serial.println("--> connection failed/n");
  }

  delay(interval);
}

timer code

#include <RBD_Timer.h>

RBD::Timer timer;

const int buttonPin = 2;     // the number of the pushbutton pin
const int buttonPin1 = 3;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int buttonState1 = 0;         // variable for reading the pushbutton status
int TijdHTTP = 20000;
int verstrekenTijd;


void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin1, INPUT);
  Serial.begin(9600);
}

void loop() {
  
  timer.setTimeout(TijdHTTP);
  
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  buttonState1 = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    timer.restart();
  } 

  if (buttonState1 == HIGH) {
    // turn LED on:
    timer.stop();
  }


  if(timer.isActive()) {
    digitalWrite(ledPin, HIGH);    // sets the LED to the button's value
    verstrekenTijd = timer.getValue();
    Serial.println(verstrekenTijd);
  }

  if(timer.isExpired()) {
    digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  }

  if(timer.isStopped()) {
    digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  }
  
}

code combined

#include <Ethernet.h> // Used for Ethernet
#include <RBD_Timer.h>

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                       
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server[] = "192.168.0.199"; // IP Adres (or name) of server to dump data 
int  interval = 5000; // Wait between dumps

RBD::Timer timer;

const int buttonPin = 2;     // the number of the pushbutton pin
const int buttonPin1 = 3;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int buttonState1 = 0;         // variable for reading the pushbutton status
int TijdHTTP = 20000;
int verstrekenTijd;
int onOffVariable = 0;

void setup() {
     // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin1, INPUT);

  Serial.begin(9600);
  Ethernet.begin(mac);

  Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
  Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  Serial.print("IP Address        : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP     : ");
  Serial.println(Ethernet.dnsServerIP());


}

void loop() {
if (client.connect(server, 80)) {
  Serial.println("-> Connected");
    
  timer.setTimeout(TijdHTTP);
  
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  buttonState1 = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    timer.restart();
  } 

  if (buttonState1 == HIGH) {
    // turn LED on:
    timer.stop();
  }


  if(timer.isActive()) {
    digitalWrite(ledPin, HIGH);    // sets the LED to the button's value
    verstrekenTijd = timer.getValue();
    Serial.println(verstrekenTijd);
    onOffVariable = 1; 
  }

  if(timer.isExpired()) {
    digitalWrite(ledPin, LOW);    // sets the LED to the button's value
    if ( onOffVariable == 1 ) {
    // Make a HTTP request:
    client.print( "GET /add_data.php?");
    client.print("serial=");
    client.print( TijdHTTP );
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(server);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
    onOffVariable = 0;
    }
  }

  if(timer.isStopped()) {
    digitalWrite(ledPin, LOW);    // sets the LED to the button's value
  }

  client.stop();
  
  } else {
    // you didn't get a connection to the server:
    Serial.println("--> connection failed/n");
  }

  delay(interval);
}

notice anything here:

// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK

that is in common with this:

const int ledPin =  13;      // the number of the LED pin

?

thanks for you reaction. I changed it to normal integers, but the problem isn't solved

sebastiaan_maes:
thanks for you reaction. I changed it to normal integers, but the problem isn't solved

hmmmm....

It doesn't matter if you refer to them as 8bit, 16 bit or even 64 bit...

How do you suppose you can use pin 13 for SPI/Ethernet and be flashing a LED connected to the same pin?

i changed the output pin to pin 5, no result :frowning:

Please post your updated combined code.

#include <RBD_Timer.h>
#include <Ethernet.h> // Used for Ethernet

RBD::Timer timer;

int buttonPin = 2;     // the number of the pushbutton pin
int buttonPin1 = 3;     // the number of the pushbutton pin
int Output =  5;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int buttonState1 = 0;         // variable for reading the pushbutton status
int TijdHTTP = 20000;
int verstrekenTijd;

// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                       
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server[] = "192.168.0.199"; // IP Adres (or name) of server to dump data 
int  interval = 5000; // Wait between dumps


void setup() {
  // initialize the LED pin as an output:
  pinMode(Output, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin1, INPUT);
  Serial.begin(9600);

  //Ethernet.begin(mac);

  Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
  Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  Serial.print("IP Address        : ");
  Serial.println(Ethernet.localIP());
  Serial.print("Subnet Mask       : ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Default Gateway IP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("DNS Server IP     : ");
  Serial.println(Ethernet.dnsServerIP());
  
}

void loop() {
  
  timer.setTimeout(TijdHTTP);
  
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  buttonState1 = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    timer.restart();
  } 

  if (buttonState1 == HIGH) {
    // turn LED on:
    timer.stop();
  }


  if(timer.isActive()) {
    digitalWrite(Output, HIGH);    // sets the LED to the button's value
    verstrekenTijd = timer.getValue();
    Serial.println(verstrekenTijd);
  }

  if(timer.isExpired()) {
    digitalWrite(Output, LOW);    // sets the LED to the button's value
  }

  if(timer.isStopped()) {
    digitalWrite(Output, LOW);    // sets the LED to the button's value
  }

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( "GET /add_data.php?");
    client.print("serial=");
    client.print( "Thomas" );
    client.print("&");
    client.print("temperature=");
    client.print( "12:00:00" );
    client.println( " HTTP/1.1");
    client.print( "Host: " );
    client.println(server);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }
  else {
    // you didn't get a connection to the server:
    Serial.println("--> connection failed/n");
  }

  
  
}