arduino basic issue

1.    string

  char Str1[15];
  char Str2[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o'};
  char Str3[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', ''};
  char Str4[ ] = "arduino";
  char Str5[8] = "arduino";
  char Str6[15] = "arduino";
字符串要有空终止符,否则它将继续向下读取字节。
你可以像这样打包长字符串: char myString[] = “This is the first line” “ this is the second line” “ etcetera”;
2.
create a arrays

创建(声明)一个数组

下面的方法都可以用来创建(声明)数组。

  myInts [6];
  myPins [] = {2,4,8,3,6};
  mySensVals [6] = {2,4,-8,3,2};
  char message[6] = "hello";
 索引下标从0开始;
3.interrupt or noInterrupt
void loop()
{
  noInterrupts();
  //重要、时间敏感的代码
  interrupts();
  //其他代码写在这里
}
中断可以被关闭或者打开。

4.attachinterrupt
a. description:两个外部中断:0(数字引脚2)和1(数字引脚3)。
    

  attachInterrupt(interrupt, function, mode)

interrupt:中断引脚树

function:中断发生时调用函数,必须没有返回值,没有参数。被称为中断服务程序

mode:定义何时发生中断以下四个contstants预定有效值:

  • LOW 当引脚为低电平时,触发中断
  • CHANGE 当引脚电平发生改变时,触发中断
  • RISING 当引脚由低电平变为高电平时,触发中断
  • FALLING 当引脚由高电平变为低电平时,触发中断.

5.tone():在一个引脚上产生特定频率的方波(50%占空比),持续时间可以设定,否则波形会一直产生直到调用no tone()函数,

 语法:tone(pin,frequency);

    tone(pin,frequency,duration)

    pin:要产生声音的引脚;

    frequency:产生声音的频率,单位hz,类型unsigned int;

    duration:声音持续的时间,单位毫秒(可选),unsigned long;

6.pulseIn():读取一个引脚的脉冲(HIGH或LOW)

语法:pulseIn(pin,value)

   pulseIn(pin,value,timeout)

   pin:要进行脉冲计时的引脚号;

      value:要读取的脉冲类型HIGH或LOW;

   timeout:指定脉冲的等待时间,单位为微秒,默认值是1秒;

7.millis():开发板从当前程序运行的毫秒数

8.constrain(x,a,b):将x约束到(a,b)范围内

9.map(value,fromLow,fromHigh,toLow,toHigh):将一个数从一个范围映射到另一个范围

  value:需要映射的值;

  fromLow:当前范围值的下限;

  fromHigh:当前范围值的上限;

  toLow:目标范围值得下限;

  toHigh:目标范围值得上限;

10.attach()

  语法:

  servo.attach(pin)

  servo.attach(pin,min,max)

  servo:舵机类型的变量

  pin :驱动舵机的管脚号

  min:脉冲宽度,对应于舵机的最小角度(0)

  max:脉冲宽度,对应于舵机的最大角度(180)

11.Mstimer2()定时器中断

MsTimer2::set(unsigned long ms, void (*f)()) ,设定定时及调用的语句
MsTimer2::start() ,定时开始
MsTimer2::stop() ,定时停止
    




原文地址:https://www.cnblogs.com/edan/p/6533071.html