• Уважаемые посетители сайта esp8266.ru!
    Мы отказались от размещения рекламы на страницах форума для большего комфорта пользователей.
    Вы можете оказать посильную поддержку администрации форума. Данные средства пойдут на оплату услуг облачных провайдеров для сайта esp8266.ru
  • Система автоматизации с открытым исходным кодом на базе esp8266/esp32 микроконтроллеров и приложения IoT Manager. Наша группа в Telegram

Вопрос return в loop()

kvn234

New member
Имею опыт программирования ATMega на WINAVR.

Для программирования ESP8266 пришлось перейти на Arduino.

В текстах программ иногда в цикле loop встречается return. Получается выход из цикла и main.

Для чего это делается и что при этом происходит с программой на ESP8266 ? Программа завершается и происходит перезагрузка?
 

Юрий Ботов

Moderator
Команда форума
Код:
int main() {
setup();
while(1)
{
loop();
}
}
ну или если интересен полный код инициализации, то вот он:
Код:
/*
  main.cpp - Main loop for Arduino sketches
  Copyright (c) 2005-2013 Arduino Team.  All right reserved.

  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 2.1 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, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <Arduino.h>

// Declared weak in Arduino.h to allow user redefinitions.
int atexit(void (* /*func*/ )()) { return 0; }

// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() { }

void setupUSB() __attribute__((weak));
void setupUSB() { }

int main(void)
{
    init();

    initVariant();

#if defined(USBCON)
    USBDevice.attach();
#endif
   
    setup();
   
    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }
       
    return 0;
}
 

Jury_78

New member
В текстах программ иногда в цикле loop встречается return. Получается выход из цикла и main.

Для чего это делается и что при этом происходит с программой на ESP8266 ? Программа завершается и происходит перезагрузка?
Вы разве с языком Си не знакомы? Поведение зависит от желания программиста. Про return - return | Аппаратная платформа Arduino
 
Сверху Снизу