아두이노 보드가 현재 프로그램을 돌리기 시작한 후 지난 밀리 초 숫자를 반환한다. 이 숫자는 약 50 일 후에 오버플로우(0으로 돌아감)가 된다.
문법
time = millis()
매개변수
없음
반환
프로그램 시작 후 지난 시간 (unsigned long)
예제 코드
이 코드는 아두이노 보드가 시작한 후 지난 밀리 초 시간을 읽는다.
unsigned long time;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("Time: ");
time = millis();
Serial.println(time); // 프로그램 시작후 지난 시간 출력
delay(1000); // 너무 많은 데이터를 보내지 않기 위해 1초 기다림
}
주의와 경고
millis ()의 반환 값은 unsigned long 이므로 프로그래머가 int 와 같은 작은 자료형으로 산술을 수행하려고하면 논리 오류가 발생할 수 있다. signed long 의 최대값의 경우도 unsigned long의 최대값의 절반이기 때문에 오류가 발생할 수 있다.
We care about the privacy and personal data of our users.
To continue, please give us your consent:
Please confirm that you have read the privacy policy
Thank you for subscribing!
Curious to learn more?
Are you also a teacher, student, or professional that loves using Arduino in your day-to-day activities?
Then keep up-to-date with either our STEM or Professional monthly newsletters.
Arduino weekly newsletter (already subscribed)
Educators can benefit from the ever growing tech that shapes our environment through fun cool projects.
Why not awe your boss with highly innovative ways to help keep your enterprise connected at no extra cost?
Arduino Survey
We'd like to get to know you little better.
Please help us improve by answering this super short optional survey.