Koduino
Functions | Variables
Keeping time

Detailed Description

Usage

  1. Call millis() or micros() to know the current time
  2. Call delay(), delayNB() or delayMicroseconds() to block execution for a duration

Example: Blink

#include <Arduino.h>
// Change to whatever pin an LED is connected to
const int led = PC13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, TOGGLE);
delay(1000);
}

Functions

static uint32_t millis () __attribute__((always_inline
 
static uint32_t micros () __attribute__((always_inline
 
void delay (uint32_t nTime)
 Blocks execution for a specified number of milliseconds. More...
 
void delayMicroseconds (uint32_t nTime)
 Blocks execution for a specified number of microseconds. More...
 
void delayNB (uint32_t nTime, ISRType iterate)
 Non-blocking delay. More...
 

Variables

volatile uint32_t _millis
 

Function Documentation

void delay ( uint32_t  nTime)

Blocks execution for a specified number of milliseconds.

Only accurate to +/- 1 ms; if you need more precision use delayMicroseconds(). Note that any code called through timer interrupts will still execute.

Parameters
nTimeNumber of milliseconds to wait
void delayMicroseconds ( uint32_t  nTime)

Blocks execution for a specified number of microseconds.

Note that any code called through timer interrupts will still execute.

Parameters
nTimeNumber of microseconds to wait
void delayNB ( uint32_t  nTime,
ISRType  iterate 
)

Non-blocking delay.

Will repeatedly execute the callback function while waiting. Note, it is preferred to use timer interrupts for this kind of functionality. FIXME: test if timebase screws up Wire or Serial communication

Parameters
nTimeNumber of milliseconds to wait
iterateFunction to call while waiting
static uint32_t micros ( )
inlinestatic

Rolls over at max of uint32_t or ~71 minutes

Returns
Time elapsed in microseconds since the start of the program
static uint32_t millis ( )
inlinestatic

Rolls over at max of uint32_t or ~50 days

Returns
Time elapsed in milliseconds since the start of the program

Variable Documentation

volatile uint32_t _millis
Authors
Avik De avikd.nosp@m.e@gm.nosp@m.ail.c.nosp@m.om

This file is part of koduino https://github.com/avikde/koduino

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, see http://www.gnu.org/licenses/.