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

Arduino Programming Basic - Funcation

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

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://parentscn.com/?id=247

标签: Arduino

相关文章

Arduino Project 024 -  LCD Temperature Display

Arduino Project 024 - LCD Temperature Display

This project is a simple demonstration of using an LCD to present useful information to the user—in...

Arduino Project 008 - RGB LED Mood Lamp

Arduino Project 008 - RGB LED Mood Lamp

In the last project, you learned how to adjust the brightness of an LED using the PWM capabilities o...

 Arduino Project 033 - 4 Digital 7 Segment Display

Arduino Project 033 - 4 Digital 7 Segment Display

Showing Heep and number 0-9 on a Common Anode 7-segment LED display. Displays the numbers 0-9 on the...

Arduino Project 014 - Light Sensor

Arduino Project 014 - Light Sensor

This project introduces a new component known as a Light Dependent Resistor, or LDR. As the name imp...

Arduino Project 030A - Dual Motor Driver L298N

Arduino Project 030A - Dual Motor Driver L298N

L298N Dual Motor Driver Project Description  The L298N Motor Driver is a control...

Arduino Project 041 - Ultrasonic Distance OLED 128X64 Display

Arduino Project 041 - Ultrasonic Distance OLED 128X64 Display

About the Ultrasonic sensor knowledge and infor mation click the link : Arduino Project 038 - S...