I have the main program
then it's call to sub-program that call to sub-sub-program.
I can't get the info from the 3rd program.
I will show an example:
void main ()
{
Serial.print ("hello");
int first();
Serial.print(d);
Serial.println(f);
}
int first ()
{
if ((digitalRead(in3)==HIGH))
{ d=0;
}
else
{
d=1;
}
int fin();
return d;
}
int fin ()
if ((digitalRead(in4)==LOW))
{
f=11111;
}
else
{
f=76
}
return f;
}
if I run the code i only get the numbers in d , but when he need to print f I only get f=0.
when I run it - it's all good and and there is no error.
By "run", I assume you mean "compile", but all that means is that the program is syntactically correct, which it probably is. However, it is possible (as it is in most languages, both natural and machine) to write things that are syntactically correct, but which make no sense.
I don't understand what you just told me.
And I don't think you understand my code - let me make it simpler
this is not the full code but it is the main idea of him.
int f,d;
void loop ()
{
one();
Serial.print(f);
Serial.print(d);
}
int one ()
{
.
.
.
why();
.
d=3
.
return d;
}
int why ()
{
.
.
.
f=453;
.
.
return f;
}
at the print I only see d=3 and f=0(when I should see f=453)
Chances are there is something in why() that is stopping it from setting f to 453. Broken logic, maybe? Who knows. Without the full code it's impossible to say.
o.k.
this is the full code that I have written - I didn't want to upload it because it's long and most of it not important for my question but if you think it will save the time and you will understand better.
the idea of the code is:
run webserver , see the status of the sensor and then print the time.
#include <SPI.h>
#include <Ethernet.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address of the device
IPAddress ip(10,0,0,25); // IP address of the device
EthernetServer server(80); //server is using port 80
int piry3=4; //the digital input of sensor1
int piro7=7; //the digital input of sensor2
int direct=5;//the digital input of the sensor3
int calibrationTime=15;// setup time
int y,x,i,d;
unsigned long updateTime;
int t=0;
int monthDay,month,year,hour,minute,second;
void setup ()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
Wire.begin();
pinMode(piry3,INPUT);
pinMode(piro7,INPUT);
pinMode(direct,INPUT);
delay(2000);
Serial.print("Please Wait - calibrating sensor ");
for(int i = 0; i < calibrationTime; i++)
{
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR IS NOW ACTIE");
delay(50);
}
void loop()
{
pir_cheak();
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// see if HTTP request has ended with blank line
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();
//meta-refresh page every 1 seconds
client.println("<HTML>");
client.print("<HEAD>");
client.print("<meta http-equiv=\"refresh\" content=\"1\">");
client.print("<TITLE /> Test</title>");
client.print("</head>");
client.println("<BODY>");
client.print("autorefresh test ");
client.println("
");
// printing the message
if
(d==0)
{
client.print("All Good - No Movement");
client.print("
");
client.print (d);
}
else
{
if (d==1)
{
for (i=0;i<5;i++)
{
client.print(" <span style=color:red>");
//<style=font-size:20pt;>");//color of message
client.print("<blink> warning -Someone Is Entering The Secure Zone!!!! </blink>");// blink the message
client.print("
");
client.print(d);
client.print("
");
client.print(monthDay);
client.print("/");
client.print(month);
client.print("/");
client.print(year);
client.print(" ");
client.print(hour);
client.print(":");
client.print(minute);
client.print(":");
client.println(second);
client.print (millis()/1000);
client.print("
");
}
client.print("<table width=25% border=2>");
client.print("<td align=center>");
client.print("LOG");
client.print("
");
client.print("msg number - ");
client.print(t);
client.print("
");
client.print("msg time - ");
client.print (millis()/1000);
client.print("
");
t++;
}
else
{
if (d==2)
{
for (i=0;i<5;i++)
{
client.print(" <span style=color:red>");
client.print("<blink> warning -Someone Is Leaving The Secure Zone!!!! </blink>");// blink the message
client.print("
");
client.print(d);
client.print("
");
client.print(monthDay);
client.print("/");
client.print(month);
client.print("/");
client.print(year);
client.print(" ");
client.print(hour);
client.print(":");
client.print(minute);
client.print(":");
client.println(second);
client.print (millis()/1000);
client.print("
");
}
client.print("<table width=25% border=2>");
client.print("<td align=center>");
client.print("LOG");
client.print("
");
client.print("msg number - ");
client.print(t);
client.print("
");
client.print("msg time - ");
client.print (millis()/1000);
client.print("
");
t++;
}
}
}
Serial.println ("END OF LOOP !!!");
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();
}
}
int pir_cheak() /// The Code of the cheaking the pir+switch status
{
if (digitalRead(direct)==LOW)
{
y=36;
if ((digitalRead(piry3)==HIGH)&&(digitalRead(piro7)==LOW))
{
d=1;
Serial.println(y);
Serial.print("WARNING!");
printDate();
delay(4000);
Serial.println("System is now Active");
}
else
{
if ((digitalRead(piry3)==LOW)&&(digitalRead(piro7)==HIGH))
{
d=2;
Serial.println(y);
Serial.print("WARNING !");
printDate();
delay(4000);
Serial.println("Active");
}
else
{
Serial.println(y);
d=0;
Serial.println("No Movement!");
Serial.println("wait for more");
}
}
}
else
if (digitalRead(direct)==HIGH)
{
x=2321;
if ((digitalRead(piry3)==HIGH)&&(digitalRead(piro7)==LOW))
{
Serial.println(x);
d=2;
Serial.println("WARNING !!!!!");
printDate();
delay(4000);
Serial.println("System is now Active");
}
else
{
if ((digitalRead(piry3)==LOW)&&(digitalRead(piro7)==HIGH))
{
Serial.println(x);
d=1;
Serial.println("WARNING!");
printDate();
delay(4000);
Serial.println("Active");
}
else
{
Serial.println(x);
d=0;
Serial.println("No Movement!");
Serial.println("wait for more");
}
}
}
return d;
}
int printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
Serial.print(monthDay);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
return monthDay,month,year,hour,minute,second;
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
when I open the web in 10.0.0.25
I can see the value of d - 0\1\2
in this line of the code : "client.print(d); "
but when I need to see the time I only get 0/0/0 0:0:0:0
(bye the way in the serial.print I can see the correct time , so it's not a problem of the clock )
every serial.print is good (this is the reason I put so many - to try to understand where is the problem)
thanks
If you want to return more values then either use a "struct" to store them in, or pass variables "by reference" (i.e., as pointers) to the function and get the function to modify those variables.
You declare a set of global variables at the top of your sketch, which are initialised to zero.
int monthDay,month,year,hour,minute,second;
but put the date into local variables in your printDate() functions
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());