在Arduino IDE的安装目录下可以找到main.cpp这个代码模板文件,main函数就位于此。

文件位置:{Arduino安装目录}\hardware\arduino\avr\cores\arduino\main.cpp,内容如下:
/*
  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;
}

Arduino学习——Arduino main 函数的更多相关文章

  1. [Go语言]从Docker源码学习Go——main函数

    Go程序从main包下的main函数开始执行,当main执行结束后,程序退出. Docker的main函数在 docker/docker/docker.go package main //Import ...

  2. Arduino学习笔记① 初识Arduino

    1.前言     近段时间,博主陆续更新了ESP8266学习笔记,主要开发平台是Arduino.但是,对于很多无基础的初学者来说,甚至不了解Arduino是什么.因此,博主决定加入一个Arduino学 ...

  3. Arduino学习经验(一)之解决舵机库和pwm输出冲突

    一.前言 最近在公司学习Arduino uno ,用它实现小车超声波避障功能.实现的功能很简单,就是在小车前方挂一个超声波模块,当碰到障碍物时,会通过舵机进行摆头,判断两边的距离,进行左右转弯.但是碰 ...

  4. Arduino 学习

    Arduino 背景可以参考官方网站www.arduino.cc 先看一个最简单的示例程序: 打开 Arduino IDE , 选择菜单:文件 -> 示例 -> 01.Basics -&g ...

  5. Arduino学习笔记1---开发环境搭建

    主要内容:(一). Arduino IDE的下载及安装 (二). Arduino IDE的应用 (三). Arduino的程序结构 (四). Arduino程序的编译及下载 (一). Arduino ...

  6. arduino上使用sprintf()函数输出float值出错

    如果尝试使用sprintf()函数在arduino上进行对float指转换为一个字符串的话,你会发现,it doesn't work.弄了很久,还以为是没学c++的原因.其实在arduino上,这个函 ...

  7. Hadoop源码学习笔记(2) ——进入main函数打印包信息

    Hadoop源码学习笔记(2) ——进入main函数打印包信息 找到了main函数,也建立了快速启动的方法,然后我们就进去看一看. 进入NameNode和DataNode的主函数后,发现形式差不多: ...

  8. Hadoop源码学习笔记(1) ——第二季开始——找到Main函数及读一读Configure类

    Hadoop源码学习笔记(1) ——找到Main函数及读一读Configure类 前面在第一季中,我们简单地研究了下Hadoop是什么,怎么用.在这开源的大牛作品的诱惑下,接下来我们要研究一下它是如何 ...

  9. 大数据学习之Scala中main函数的分析以及基本规则(2)

    一.main函数的分析 首先来看我们在上一节最后看到的这个程序,我们先来简单的分析一下.有助于后面的学习 object HelloScala { def main(args: Array[String ...

随机推荐

  1. PLsql的汉化工具

    链接:https://pan.baidu.com/s/19J-px5I_7qcMb5CHDwJZZQ 密码:pr89

  2. axios和fetch

    前面的vuex提到了异步请求,在vue里异步请求怎么请求呢,很显然jq.ajax是不用了,不是不能用,而是没必要,jq是操作dom的工具,强行用浪费功能,还会加大打包后的体积,而且是没有promise ...

  3. solus linux 更新源

    添加源(清华大学开源软件镜像)sudo eopkg ar Solus https://mirrors.tuna.tsinghua.edu.cn/solus/shannon/eopkg-index.xm ...

  4. 007-PHP变量和函数相互转换

    <?php function write($text) //定义function write()函数 { print($text); //打印字符串 } function writeBold($ ...

  5. Educational Codeforces Round 64 选做

    感觉这场比赛题目质量挺高(A 全场最佳),难度也不小.虽然 unr 后就懒得打了. A. Inscribed Figures 题意 给你若干个图形,每个图形为三角形.圆形或正方形,第 \(i\) 个图 ...

  6. leetcode1143 Longest Common Subsequence

    """ Given two strings text1 and text2, return the length of their longest common subs ...

  7. leetcode1042 Flower Planting With No Adjacent

    """ You have N gardens, labelled 1 to N. In each garden, you want to plant one of 4 t ...

  8. JuJu团队11月26号工作汇报

    JuJu团队11月26号工作汇报 JuJu   Scrum 团队成员 今日工作 剩余任务 困难 于达 对原始文本进行预处理, 并转换成可被julia读入的格式 完成预处理并用julia读入. 读入后按 ...

  9. POJ2533:Longest Ordered Subsequence

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 37454   Acc ...

  10. Linux 安装gcc g++

    Linux版本: cat /proc/version Linux version 3.10.0-693.11.6.el7.x86_64 (mockbuild@x86-041.build.eng.bos ...