Hi,
first of all, i have to say that i am really really new to arduino/microcontrollers and programming!
so here are my questions:
i have a Arduino here, with a RTC, an ethernet shield, and a stepper motor. i can somehow use all the parts seperately, but i am wondering how to put them together.
The code is the following:
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include "RTClib.h"
#include <Stepper.h>
RTC_DS1307 RTC;
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 53,52,51,50);
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,10,10);
int st,mi,se;
EthernetServer server(80);
void setup() {
myStepper.setSpeed(60);
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop () {
DateTime now = RTC.now();
DateTime korrekt (now.unixtime() - 960);
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("UHRZEIT ");
client.print(korrekt.hour(), DEC);
client.print(":");
client.print(korrekt.minute(), DEC);
client.print(":");
client.print(korrekt.second(), DEC);
client.println("
");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
How could i get the stepper motor to do x steps everytime "korrekt.second(), DEC" is 10?
and second: why is the RTC around 960s offset to the real time?
I hope these questions are not too basic for you guys here, and i hope someone can help me!
Thanks a lot!!
PS.: i tried something like:
se = korrekt.second(), DEC;
if (se = 10) {
myStepper.step(1000);
}
but it simply did nothing .... Ideas?