当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Programming Basic - Funcation

RonWang1年前 (2024-04-15)电子编程384

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静态变量,数据类型,Bollean运算,注释语句等。

Funcations 函数

Functions in C and arduino

Flash 函数 2-1

int ledPin=13;
int delayPeriod =200;

void setup()
{
pinMode(ledPin,OUTPUT);
}

void loop()
{ 
  flash(20, delayPeriod);
  delay(3000);
 }
 
 void flash(int numFlashes, int d)
 {
  for( int i=0; i<numFlashes; i++)
   { digitalWrite(ledPin,HIGH);
     delay(d);
     digitalWrite(ledPin,LOW);
     delay(d);
  }
  }

函数的返回值 Return 2-2

int centToFaren(int c)
{
int f= c*9/5+32;
return f;
}
//函数调用

int pleasantTemp =centToFaren(20);

Code written on Arduino IDE Software

版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://www.parentscn.com/?id=247

标签: Arduino

相关文章

 Arduino Project 043 - SD CardTemperature Datalogger

Arduino Project 043 - SD CardTemperature Datalogger

Todady I made a simple Arduino datalogger using SD card and DHT11  relative humidity and t...

Arduino Project 025 - Servo Control

Arduino Project 025 - Servo Control

You will need to obtain a standard RC servo; any of the small or mid-sized servos will do. Larger se...

Arduino Project 009 - LED Fire Effect

Arduino Project 009 - LED Fire Effect

Project 9 will use LEDs and a flickering random light effect, via PWM again, to mimic the effect of...

​Arduino Project 046 - Based Security System by Arduino with Lcd Display

​Arduino Project 046 - Based Security System by Arduino with Lcd Display

Arduino Project 046 - Based Security System by Arduino with Lcd Display/*  * Project ...

Arduino Project 005 - LED Chase Lights

Arduino Project 005 - LED Chase Lights

You’re going to use a string of LEDs (10 in total) to make an LED chase effect, similar to that used...

 ​Arduino Project 048 - Human Body Infrared Detector and Relay Light

​Arduino Project 048 - Human Body Infrared Detector and Relay Light

Project 48 Human Body Infrared Detector and Relay Light/*  * Coding by Ronwang&...