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', '\0'}; 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:中断引脚树oop

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

mode:定义什么时候发生中断如下四个contstants预约有效值:this

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

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

 语法:tone(pin,frequency);spa

    tone(pin,frequency,duration)code

    pin:要产生声音的引脚;索引

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

    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() ,定时中止
相关文章
相关标签/搜索