赞
踩
新建Arduino程序,只看到了setup和loop函数,却没有基本的C/C++函数
查看源代码:
#include <Arduino.h>
int main(void)
{
init();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}
找到main函数,看到main函数里在初始化时调用了setup函数,在for循环里调用了loop函数,
arduino中:
看一个碰触传感器的代码:
const int buttonPin = A0 ;
// the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0;
// variable for reading the pushbutton status
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == LOW)
{
// turn LED on:
digitalWrite(ledPin,HIGH );
}
else
{
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。