error message

hi
i get an error message " cannot find a class or a type named GregorianCalendar"
What can i do ?
its in time library in examples SyncArduinoClock.
Thanks

Doc1.docx (122 KB)

Is SyncArduinoClock a Processing program or an Arduino program ?

How to use this forum

Please use code tags.

Read this before posting a programming question

I'm not interested in loading a Word document. Post your code.

/**
 * SyncArduinoClock. 
 *
 * portIndex must be set to the port connected to the Arduino
 * 
 * The current time is sent in response to request message from Arduino 
 * or by clicking the display window 
 *
 * The time message is 11 ASCII text characters; a header (the letter 'T')
 * followed by the ten digit system time (unix time)
 */


import processing.serial.*;

public static final short portIndex = 1;  // select the com port, 0 is the first port
public static final char TIME_HEADER = 'T'; //header byte for arduino serial time message 
public static final char TIME_REQUEST = 7;  // ASCII bell character 
public static final char LF = 10;     // ASCII linefeed
public static final char CR = 13;     // ASCII linefeed
Serial myPort;     // Create object from Serial class

void setup() {  
  size(200, 200);
  println(Serial.list());
  println(" Connecting to -> " + Serial.list()[portIndex]);
  myPort = new Serial(this,Serial.list()[portIndex], 9600);
}

void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    char val = char(myPort.read());         // read it and store it in val
    if(val == TIME_REQUEST){
       long t = getTimeNow();
       sendTimeMessage(TIME_HEADER, t);   
    }
    else
    { 
       if(val == LF)
           ; //igonore
       else if(val == CR)           
         println();
       else  
         print(val); // echo everying but time request
    }
  }  
}

void mousePressed() {  
  sendTimeMessage( TIME_HEADER, getTimeNow());   
}


void sendTimeMessage(char header, long time) {  
  String timeStr = String.valueOf(time);  
  myPort.write(header);  // send header and time to arduino
  myPort.write(timeStr);   
}

long getTimeNow(){
  // java time is in ms, we want secs    
  
GregorianCalendar cal = new GregorianCalendar();
  cal.setTime(new Date());
  int  tzo = cal.get(Calendar.ZONE_OFFSET);
  int  dst = cal.get(Calendar.DST_OFFSET);
  long now = (cal.getTimeInMillis() / 1000) ; 
  now = now + (tzo/1000) + (dst/1000); 
  return now;
}

This is the code, Process code

Moderator edit: code tags.

How does the Processing code, and error message when compiling it, relate to the Arduino? Perhaps they could help you at http://www.Toyota.com.

This is a processing code that supose to be working with arduino.
How can Toyota help me?
The error message is about “GregorianCalendar”, not related to arduino, it seems that samething is wrong with the code but i don’t know what.

How can Toyota help me?

They can't. But, you have a Processing problem, not an Arduino problem.

You are trying to use a class that is not defined anywhere. Typically, that requires that you import the correct library (similar to #include statement in C/C++). Where you get that is a mystery to me. You've posted some code that you haven't said where you got.

I managed to run it. I was missing java.util.* Thank you anyway for your atention. Maybe you know how to show the time on LCD?