Как сделать delay меньше 1 на ардуино

от admin

Arduino.ru

Останавливает выполнение программы на заданное в параметре количество миллисекунд (1000 миллисекунд в 1 секунде).

Синтаксис
Параметры

ms: количество миллисекунд, на которое приостанавливается выполнение программы. (unsigned long)

Возвращаемое значение
Пример
Замечания по использования функции

Не рекомендуется использовать эту функцию для событий длиннее 10 миллисекунд, т.к. во время останова, не могут быть произведены манипуляции с портам, не могут быть считаны сенсоры или произведены математические операции. В качестве альтернативного подхода возможно контролирование времени выполнения тех или иных функций с помощью millis().

Большинство активности платы останавливается функцией delay(). Тем не менее работа прерываний не останавливается, продолжается запись последовательно (serial) передаваемых данных на RX порту, ШИМ сигнал (analogWrite) продолжает генерироваться на портах.

delay()

ms : the number of milliseconds to pause. Allowed data types: unsigned long .

Returns

Example Code

The code pauses the program for one second before toggling the output pin.

Notes and Warnings

While it is easy to create a blinking LED with the delay() function and many sketches use short delays for such tasks as switch debouncing, the use of delay() in a sketch has significant drawbacks. No other reading of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect, it brings most other activity to a halt. For alternative approaches to controlling timing see the Blink Without Delay sketch, which loops, polling the millis() function until enough time has elapsed. More knowledgeable programmers usually avoid the use of delay() for timing of events longer than 10’s of milliseconds unless the Arduino sketch is very simple.

Certain things do go on while the delay() function is controlling the Atmega chip, however, because the delay function does not disable interrupts. Serial communication that appears at the RX pin is recorded, PWM (analogWrite) values and pin states are maintained, and interrupts will work as they should.

Функции времени

Простейшей с точки зрения использования функцией времени является задержка: программа “зависает” внутри функции задержки и ожидает указанное время. Задержка позволяет очень удобно и наглядно организовать работу простой “однозадачной” программы, у нас есть два варианта задержек:

  • delay(time)
    • Задержка на указанное количество миллисекунд (мс). 1 секунда = 1’000 мс.
    • time принимает тип данных unsigned long и может приостановить выполнение на срок от 1 до 4 294 967 295 мс (

    • Задержка на указанное количество микросекунд (мкс). 1 секунда = 1’000’000 мкс.
    • time принимает тип данных unsigned int и может приостановить выполнение на срок от 4 до 16383 мкс (да, меньше чем максимум для этого типа данных) с разрешением 4 мкс.
    • Работает не на таймере, а на пропуске тактов процессора, поэтому может работать в прерывании и при отключенных прерываниях.
    • Иногда не совсем корректно работает с переменными, поэтому нужно стараться использовать константы ( const или просто число).
    • Часто используется в библиотеках для эмуляции цифровых интерфейсов связи.

    Задержки использовать очень просто:

    Мышление “задержками” – главная проблема новичков. Организовать работу сложной программы при помощи задержки – невозможно, поэтому дальше рассмотрим более полезные инструменты.

    Функция yield()

    Разработчики Arduino позаботились о том, чтобы функция delay() не просто блокировала выполнение кода, но и позволяла выполнять другой код во время этой задержки. Данный “костыль” получил название yield() и работает следующим образом: если объявить функцию

    то расположенный внутри неё код будет выполняться во время работы любой задержки delay() в программе! Это решение хоть и кажется нелепым, но в то же время позволяет быстро и без написания лишних костылей и таймеров реализовать пару параллельно выполняющихся задач. Это вполне соответствует идеологии Arduino – максимально простая и быстрая разработка прототипа. Рассмотрим простой пример: стандартный мигающий светодиод, но с опросом кнопки:

    Функции счёта времени

    Данные функции возвращают время, прошедшее с момента запуска программы, так называемый аптайм (англ. uptime). Таких функций у нас две:

      millis() – миллисекунды, тип unsigned long , от 1 до 4 294 967 295 мс (

    Эти функции позволяют организовать программу практически любой сложности с любым количеством параллельно выполняющихся по таймеру задач. Подробнее об этом поговорим в уроке про многозадачность.

    millis() в часы и секунды

    Миллисекунды – не самый удобный способ оценить время работы программы. Можно перевести его в более человеческие часы, минуты и секунды при помощи нехитрых математических операций:

    Arduino delay millis и micros для организации задержки в скетче

    Arduino millis() is not accurate and one reason for this is that Arduino
    boards sometimes have a 16MHz resonator fitted. This is a cheap oscillation
    component that is OK for most applications. it will drift around with
    temperature but will always be approximately 16MHz.

    If you are looking for accuracy, you will need an Arduino with a crystal on
    board (or make up your own bare-bones version with a crystal). You can tell if
    yours only has a resonator as resonators are three pin devices whereas crystals
    are two pin devices.

    The problem is that to retro fit a crystal (it can be done!) to an Arduino
    board requires two extra components to make the crystal oscillate correctly
    (capacitive loads are required). These are two capacitors, each connected to
    one pin of the crystal and then to ground. They range from 12pF to 33pf — check
    for the correct capacitor specified by the manufacturer — or just use a couple
    of 15pF. You of course also need to attach the crystal to the clock inputs of
    the microcontroller (same connections as the resonator — but not the middle
    ground one).

    A better solution
    is to use an external RTC

    The accuracy of the crystal is specified as ppm and is usually around 100ppm
    (a 32kHz watch crystal can get to 20ppm — not much use for a microcontroller
    unless you need low power operation).

    If you really want an accurate timestamp then use an ovenised timekeeping
    chip (a cheap 2ppm one is the DS3232). This does not output a clock for direct
    use by the microcontroller so you could keep the resonator and use the
    DS3232 as the accurate timestamp device.

    More on the delay() function

    Let’s talk a little bit more about this delay function. What have we established so far?

    First we’ve said the delay function decreases the tightness of a loop. If you have a tight loop and you add the delay function, it’s going to take more time and make it less tight. That is, the amount of time it takes to get from the start of the loop to the bottom, will increase with the delay function.

    We also know that the delay function blocks code. This goes hand in hand with what we just said. When the delay function is running, it is blocking other code from running while it’s delaying.

    You might think this delay function is a total slacker! It’s never going to amount to anything in our projects. But for a lot of simple programs that we write, the delay function works fantastic. It’s simple to use, it’s really easy to spell, and it does just what it says.

    There is a time when you start to run into issues, however. That has to do with the blocking effect that the delay function has in our program.

    In the next lesson in the series, part 3, we’re going to identify where this really becomes an issue. You’ll learn when it makes sense to use the delay() function in a program, and when it’s time to switch to using the millis() function.

    Other values of Arduino Crystal Clock

    Elsewhere in the code (microsecond delay) it talks about the following
    frequencies:

    ‘Assumes a 1, 8, 12, 16, 20 or 24 MHz’

    (the 24MHz clock is for overclocking — doing something not specified by the
    data sheet).

    The question is: Would millis() be accurate for these crystals?

    The following
    results show that for most cases the millis() output would be accurate but not
    for 12, 20 and 24MHz. You would need to change the operation of the Arduino
    code to make millis() output an accurate result.

    Microseconds per timer0 overflow:

    (64 * 256.0) / 1 = 16384 — 1MHz — no error.

    (64 * 256.0) / 2 = 8192 — 2MHz — no error.

    (64 * 256.0) / 4 = 4096 — 4MHz — no error.

    (64 * 256.0) / 8 = 2048 — 8MHz — no error.

    (64 * 256.0) / 12 = 1365.33 — 12Mhz — millis() would have an error.

    (64 * 256.0) / 16 = 1024 — 16MHz — no error.

    (64 * 256.0) / 20 = 819.2 — 20MHz — millis() would have an error.

    (64 * 256.0) / 24 = 682.66 — 24MHz — millis() would have an error.

    The calculation below is FRACT_INC (microseconds_per_interrupt % 1000) >> 3

    Frequency (MHz) FRACT_INC increments
    1 48
    2 24
    4 12
    8 6
    12 45 (Not accurate millis o/p).
    16 3
    20 102 (Not accurate millis o/p).
    24 85 (Not accurate millis o/p).

    Note: Observe how FRACT_INC values blow up when the frequency used is not an exact
    factor of the Timer0 prescaler and overflow result. Since pre-scalers and timers
    use 8 or 16 bits it follows that for this scheme the clock frequency must be a
    base2 value i.e. 1,2,4,8,16,32 etc.

    Note: At lower crystal frequencies the value of FRACT_INC is
    larger but the shifted right value of 1000 ms calculations remains the same —
    it has a value of 125 — to fit into a byte) . Therefore the jitter will be far
    greater using lower frequences i.e. the millisecond clock will be corrected more
    often. e.g. for 16MHz 125/3 is 41.6 but 125/48 is 2.6 — so at 16Mhz the clock
    is corrected every 42 ms while at 1MH it is corrected every 3ms.

    What happens if
    you use Arduino millis long?

    If you decide to use a «long» type
    definition for the comparison storage variable then you are using a signed
    quantity instead of the unsigned quantity output by the millis() function.

    If you were to make a timer using «long» and output the value of long using
    a Serial command (or any command that converts an integer quality to a string)
    such as:

    …where timer is specified as long and updates, perhaps to seconds as:

    Then at some point in the operation of your code (when the timer reaches the
    mid point) the leftmost bit of the unsigned output of millis() will become high
    and the print function will interpret this a the sign bit. Therefore it will
    output a negative number and Arduino millis() goes negative (or appears to be
    negative). For a signed calculation the value is interpreted as negative and
    the print function treats long as a signed quality and therefore outputs a
    negative number.

    Try this of code in Arduino

    Example of unsigned long millis overflow

    Lets say ledtime is set to the maximum value of the unsigned long:

    ledtime = 0xffffffff or pow(2,32)-1 or 4294967295

    That means when the next timeout detection is performed then millis()
    will retrurn a positive value and lets say that millis() returns a value of 1 on
    the next detection then for normal maths you would have:

    millis() — ledtime == 1 — 4294967295 = -4294967294

    The the twos complement and modulo maths means for an unsigned long this represents:

    So this is the right answer even though millis() value is smaller than the
    real value of ledtime. Twos complement maths means that $fffffff is
    interpreted as a negative number ($fffffff == -1). So:

    ledtime (1) — ($ffffffff) == (1) — (-1) == 2.

    Time Conversions for
    Arduino millis

    Millis() Operation

    At each interrupt of 1024us the millis() timer is incremented.
    Since 1024us is greater than 1000us, the millis() timer is too slow and needs correcting.

    The idea is to store the error and
    accumulate it until it surpasses a threshold, upon which the
    millisecond timer output is corrected.

    So to correct to a 1ms output, The number of interrupts before a correction is needed is:

    The above equation represents the number of 24us periods that add up
    to 1ms i.e after 41.66 interrupts the error will be 1ms. Of course you
    can’t get 41.66 interrupts so you have to wait for the following
    interrupt to detect when the error is greater than 1000us. This will be
    when 42 interrupts have occurred.

    The clever part of the algorithm is that the error accumulator is
    incremented by 24 every interrupt (the division is not performed — that
    just lets you see the idea). When this variable is greater than 41.66*24
    i.e 42*24 = 1008 then the error is corrected.

    The next really, really, clever part of the algorithm is that the
    error variable is not reset to zero — you just subtract the 1ms value
    (since that was what was corrected) leaving the last value of the error
    in the accumulator i.e. it will be 8 on this occasion. This error then
    accumulates again and the millis() timer is again adjusted when the error is greater then 1ms.

    From the analysis below the millis() timer will be
    continuously corrected and is not in error by more than 2ms (See simulation and real output results below).

    You can explore this further by looking at the code
    that follows below. One thing to note is that the values are fitted into
    bytes because they are all multiples of 8 (but this only works for 16MHz and 8MHz
    clocks):

    1024.0 / 8 = 128.0 ; 1024 >> 3 is exactly 128 i.e. fits in a byte.

    1000.0 / 8 = 125.0 ; 1000 >> 3 is exactly 125 i.e. fits in a byte.

    24.0 / 8 =
    3.0 ; 24
    >> 3 is exactly 3 i.e. fits in a byte.

    These numbers are used in the code below.

    Ардуино задержка включения / выключения

    Для этого занятия нам потребуется:

    плата Arduino Uno / Arduino Nano / Arduino Mega.

    В этой записи мы рассмотрим только основные характеристики функций задержки, а примеры использования представим в виде небольших скетчей. Для работы вам потребуется только сама плата Ардуино. Начнем обзор с delayMicroseconds Arduino, т.к. данную функцию не часто можно встретить в программах, а также рассмотрим, как заменить задержку delay на millis в программировании Arduino IDE.

    Ардуино delayMicroseconds()

    Команда delayMicroseconds останавливает выполнение программы на заданное количество микросекунд (в 1 секунде 1 000 000 микросекунд). При необходимости задержки в программе более чем на несколько тысяч микросекунд рекомендуется использовать delay(). Продемонстрируем на простом примере использование функции в скетче для мигания встроенным светодиодом на плате Arduino.

    Ардуино delay()

    Команда delay останавливает выполнение программы на заданное количество миллисекунд (в 1 секунде 1 000 миллисекунд). Во время задержки программы с помощью функции delay(), не могут быть считаны подключенные к плате датчики или произведены другие операции, например, запись в еепром Ардуино данных. В качестве альтернативы следует использовать функцию millis(). Смотри пример далее.

    Ардуино millis()

    Команда millis возвращает количество прошедших миллисекунд с момента начала выполнения программы. Счетчик времени сбрасывается на ноль при переполнении значения unsigned long (приблизительно через 50 дней). Функция miilis позволяет сделать многозадачность Ардуино, так как выполнение программы не останавливается и можно выполнять параллельно другие операции в скетче.


    Arduino команды millis, delay, delaymicroseconds

    How to make a simple scheduler using Arduino millis

    The aim of this Arduino millis example is to make a simple scheduler
    algorithm to start different actions at different times. This is only a simple
    example and you can find multitasking schedulers that transfer operation to a
    different task saving variables so that tasks can be interrupted stopped and
    restarted. There will also be the concept of flags that allow communication
    between tasks. This simple example is definitely not that type but it can be
    useful nevertheless.

    Scheduling initial times for offset start using Arduino millis

    TIP: To avoid everything happening at the same time set
    the initial conditions to be offset from each othe.

    You can offset the start times of each timer so that they are not all a multiple of 1000, because if
    they are then they will fire more or less at the same time and serial output
    will be generated, and serial output takes a bit of time thus changing the
    actual time that subsequent time matches happen.

    For example you could write the following initialisation (using random
    offsets):

    This would mean that the starting times of each timed output are offset from
    each other — only the start times — the subsequent repeat times would be at the
    repeat time specified in the code — they would still be offset so they would
    not happen at the exact same time.

    So the processor would not have to do the
    actions associated with each timeout at the same time. Therefore the code will
    operate more smoothly and not have to do a big processing burp!

    Privacy Policy
    | Contact
    | About MeSite Map
    | Terms of Use

    Исходный код программы

    Далее приведен полный текст программы. Работа нашего проекта продемонстрирована на видео, приведенном в конце статьи.

    #include<LiquidCrystal.h> //подключение библиотеки для работы с ЖК дисплеем
    #define ledPin 7
    LiquidCrystal lcd(8,9,10,11,12,13);
    float value = 3035; //Preload timer value (3035 for 4 seconds)
    void setup()
    <
    lcd.begin(16,2);
    lcd.setCursor(0,0);
    lcd.print(«ARDUINO TIMERS»);
    delay(2000);
    lcd.clear();

    pinMode(ledPin, OUTPUT);
    pinMode(2,INPUT);
    pinMode(4,INPUT);

    noInterrupts(); // отключаем все прерывания

    TCCR1A = 0;
    TCCR1B = 0;
    TCNT1 = value; // preload timer
    TCCR1B |= (1 << CS10)|(1 << CS12); // 1024 prescaler (коэффициент деления предделителя)
    TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt ISR (разрешаем вызов процедуры обработки прерывания переполнения счетчика)
    interrupts(); // разрешаем все прерывания
    >
    ISR(TIMER1_OVF_vect) // процедура обработки прерывания переполнения счетчика
    <
    TCNT1 = value; // preload timer
    digitalWrite(ledPin, digitalRead(ledPin) ^ 1); //включаем и выключаем светодиод
    >
    void loop()
    <
    if(digitalRead(2) == HIGH)
    <
    value = value+10; //Incement preload value
    >
    if(digitalRead(4)== HIGH)
    <
    value = value-10; //Decrement preload value
    >
    lcd.setCursor(0,0);
    lcd.print(value);
    >

    #include<LiquidCrystal.h> //подключение библиотеки для работы с ЖК дисплеем
    #define ledPin 7

    floatvalue=3035;//Preload timer value (3035 for 4 seconds)

    noInterrupts();// отключаем все прерывания

    TCNT1=value;// preload timer

    TCCR1B|=(1<<CS10)|(1<<CS12);// 1024 prescaler (коэффициент деления предделителя)

    TIMSK1|=(1<<TOIE1);// enable timer overflow interrupt ISR (разрешаем вызов процедуры обработки прерывания переполнения счетчика)

    interrupts();// разрешаем все прерывания

    ISR(TIMER1_OVF_vect)// процедура обработки прерывания переполнения счетчика

    TCNT1=value;// preload timer

    digitalWrite(ledPin,digitalRead(ledPin)^1);//включаем и выключаем светодиод

    value=value+10;//Incement preload value

    value=value-10;//Decrement preload value

    Кухонный таймер Ардуино с энкодером

    Сейчас рассмотрим, как сделать таймер на Ардуино своими руками с энкодером и LCD. Принцип управления, подобен предыдущему варианту. Поворотом ручки энкодера можно задать необходимый временной интервал, а нажатием на ручку можно запускать и останавливать обратный отсчет времени. Далее размещена схема сборки проекта на Arduino Nano, этот проект можно собрать и на плате Arduino Uno.

    Скетч таймера обратного отсчета времени

    Пояснения к коду:
    1. частоту звукового сигнала можно изменить через команду tone();
    2. для скетча потребуется установить библиотеку RotaryEncoder.

    Что лучше: millis() или delay()

    Такая, казалось бы, простая и часто используемая функция, как delay(), может являться источником трудноуловимых ошибок. Давайте рассмотрим, когда ее можно использовать, а когда нет.

    Итак, как работает функция delay()? Она останавливает выполнение программы на заданное количество миллисекунд. Например, если нам нужно, чтобы спикер пропищал 1 секунду, мы напишем следующий код:

    Или нам нужно опрашивать какой-либо датчик 1 раз в 5 секунд:

    Все это будет работать правильно. Но давайте немного усложним задачу. Например, нам нужно раз в 5 секунд получать данные с датчика, а по нажатию на кнопку, выводить их на экран:

    И вот тут мы столкнемся с ситуацией, когда наша кнопка не всегда отрабатывает по нажатию. Обратимся к :

    Это означает, что если во время выполнения функции delay() будет нажата кнопка, то наш код не отработает. Причем, если при задержке в 5 секунд, как в примере, мы это увидим сразу, то если задержка будет небольшая, то нажатия не будут срабатывать только в редких случаях. А если код скетча будет сильно сложный, то ошибку найти будет довольно непросто.

    Итак, что же делать? И тут нам на помощь приходит замечательная функция millis().Из :

    Перепишем код последнего примера на ее использование:

    Итак, поясню, что же здесь происходит. В LOOP_MILLIS мы помещаем требуемое время задержки — 5000 миллисекунд.В начале функции loop() на строке 7 мы определяем статическую переменную lastLoop и инициализируем ее нулем

    Обратите внимание, что значение 0 будет ей присвоено только при первом вызове функции loop() (советую ознакомиться со статьей про статические переменные и преимущества их использования).
    Далее (строчка 9) создается уже обычная локальная переменная now, в которую помещается значение миллисекунд, прошедших с момента запуска скетча. Строчки 10-12 пока пропускаем

    И на строке 14 видим условие, в теле которого мы вызывает действия, которые нужно повторять каждые 5 секунд, и перезаписываем переменную lastLoop текущим значением переменной now. Таким образом мы сохранили время последнего вызова нашей операции. И далее, она будет вызвана тогда, когда с момент последнего ее вызова прошло 5 секунд (что и означает условие на строчке 14).Теперь вернемся к строчкам 10-12. Вспомним, что в документации по функции millis() было написано, что примерно раз в 50 дней происходит переполнение и функция вновь будет возвращать значения начиная с 0. Поэтому необходимо проверить, что произошло переполнение (только при переполнении значение переменной lastLoop, которая содержит время последнего запуска, может быть больше, чем значение переменной now), и также обнуляем переменную lastLoop. Если этого не сделать, то условие на строке 14 просто перестанет выполняться, так как now всегда будете меньше, чем lastLoop.

    ← Выбираем лучшую среду разработки: Arduino IDE или PlatformIO

    Что использовать: статические или глобальные переменные →

    Моргание без команды Delay [1]

    Иногда в процессе работы может потребоваться, чтобы два процесса проходили одновременно. К примеру, может понадобиться, чтобы светодиод моргал каждый раз, когда система будет считывать нажатие на кнопку. В этом случае функцию delay() использовать нельзя – руководствуясь ею, Arduino приостановит действие программы и потому просто «проморгает» факт нажатия на кнопку.
    Скетч ниже демонстрирует, как заставить светодиод моргать, не используя при этом функцию delay(). Код заставляет светодиод включиться, а затем отмечает время. Затем, проходя через loop(), проверяет, не закончилось ли время, отведенное программой на режим «вкл». Если закончилось, он выключает светодиод и снова отмечает время. Потом ждет, когда закончится нужный интервал и снова включает светодиод. И так по кругу

    То есть этот код заставляет светодиод непрерывно моргать.
    В качестве аналогии можно привести такую ситуацию – допустим, вы разогреваете в микроволновке пиццу и в то же время ждете важного телефонного звонка. Вы кладете пиццу в микроволновку и включаете ее на 10 минут

    То есть, если сравнить это с использованием функции delay(), то вы как бы сидите перед микроволновкой и ждете, когда таймер отсчитает эти 10 минут, но, услышав звонок, вдруг убегаете в другую комнату снимать трубку, тем самым «проморгав» момент икс – 10 минут превратятся в 11, 12, 13 и т.д., пока пицца не превратится в обуглившуюся лепешку.
    Но это пример из выдуманной вселенной, где у микроволновки нет таймера. В нашей же вселенной он есть, благодаря чему во время подогрева пиццы вы можете и разговаривать по телефону, и читать «имейлы», и сидеть в соцсети (но не слишком долго – пицца остынет!), будучи уверенным, что по прошествии этих 10 минут микроволновка выключится и пицца будет в идеальной кондиции.
    В данном примере мы как раз научимся делать подобный таймер.

    Программирование Ардуино

    Язык программирования устройств Ардуино основан на C/C++. Он прост в освоении, и на данный момент Arduino — это, пожалуй, самый удобный способ программирования устройств на микроконтроллерах.

    Базовые и полезные знания, необходимые для успешного программирования под платформу Arduino:

    • Начало работы с Arduino в Windows
    • Работа с Arduino Mini
    • Цифровые выводы
    • Аналоговые входы
    • Широтно-импульсная модуляция
    • Память в Arduino
    • Использование аппаратных прерываний в Arduino
    • Переменные
    • Функции
    • Создание библиотек для Arduino
    • Использование сдвигового регистра 74HC595 для увеличения количества выходов
    • Прямое управления выходами через регистры микроконтроллера Atmega
    Справочник языка Ардуино

    Язык Arduino можно разделить на три раздела:

    Операторы

    • setup()
    • loop()
    Управляющие операторы
    • if
    • if…else
    • for
    • switch case
    • while
    • do… while
    • break
    • continue
    • return
    • goto
    Синтаксис
    • ; (semicolon)
    • <> (curly braces)
    • // (single line comment)
    • /* */ (multi-line comment)
    Арифметические операторы
    • = (assignment)
    • + (addition)
    • — (subtraction)
    • * (multiplication)
    • / (division)
    • % (modulo)
    Операторы сравнения
    • == (equal to)
    • != (not equal to)
    • < (less than)
    • > (greater than)
    • <= (less than or equal to)
    • >= (greater than or equal to)
    Логические операторы
    • && (И)
    • || (ИЛИ)
    • ! (Отрицание)
    Унарные операторы
    • ++ (increment)
    • — (decrement)
    • += (compound addition)
    • -= (compound subtraction)
    • *= (compound multiplication)
    • /= (compound division)

    Данные

    Константы
    • HIGH | LOW
    • INPUT | OUTPUT
    • true | false
    • Целочисленные константы
    • Константы с плавающей запятой
    Типы данных
    • boolean
    • char
    • byte
    • int
    • unsigned int
    • word
    • long
    • unsigned long
    • float
    • double
    • string — массив символов
    • String — объект класса
    • массив (array)
    • void
    Преобразование типов данных
    • char()
    • byte()
    • int()
    • long()
    • float()
    Область видимости переменных и квалификаторы
    • Область видимости
    • static
    • volatile
    • const

    Функции

    Цифровой ввод/вывод
    • pinMode()
    • digitalWrite()
    • digitalRead()
    Аналоговый ввод/вывод
    • analogRead()
    • analogReference()
    • analogWrite()
    Дополнительные фунции ввода/вывода
    • tone()
    • noTone()
    • shiftOut()
    • pulseIn()
    Работа со временем
    • millis()
    • micros()
    • delay()
    • delayMicroseconds()
    Математические функции
    • min()
    • max()
    • abs()
    • constrain()
    • map()
    • pow()
    • sq()
    • sqrt()
    Тригонометрические функции
    • sin()
    • cos()
    • tan()
    Генераторы случайных значений
    • randomSeed()
    • random()
    Внешние прерывания
    • attachInterrupt()
    • detachInterrupt()
    Функции передачи данных
    Библиотеки Arduino

    Servo — библиотека управления сервоприводами.EEPROM — чтение и запись энергонезависимой памяти микроконтроллера.SPI — библиотека, реализующая передачу данных через интерфейс SPI.Stepper — библиотека управления шаговыми двигателями.

    Example #2: Basic Delay with for() loops

    For our 2nd example, we are only going to delay for 1ms, but do so inside of a for() loop.

    This new sketch will accomplish the same sequence as Example #1. The difference is that the Arduino is only “delayed” for one millisecond at a time. A clever trick would be to call other functions inside of that for() loop. However, your timing will be off because those instructions will add additional delay.

    Читать:
    Какой ток холостого хода трансформатора нормальный

Похожие публикации