这是Arduino 控制LED灯的代码,请问这段代码什么意思? 5
constintledPin=3;//thenumberoftheLEDpinvoidsetup(){//putyoursetupcodehere,torunonce:S...
const int ledPin = 3; // the number of the LED pin
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
//digitalWrite(ledPin, LOW);
}
char i = 255;
int sensorValue = 0;
unsigned char aa,bb;
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
unsigned char a = Serial.read();
if(a == 170)
{
delay(10);
aa = Serial.read();
delay(10);
bb = Serial.read();
}
}
sensorValue = analogRead(A0);
sensorValue = 1024 - sensorValue ;
sensorValue = sensorValue * 0.25;
if(aa == 0x01)
{
analogWrite(ledPin,sensorValue);
}
else
{
analogWrite(ledPin,255-bb);
}
Serial.write(0xaa);
Serial.write(0x01);
Serial.write(0x01);
Serial.write(sensorValue&0xff);
delay(100);
} 展开
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
//digitalWrite(ledPin, LOW);
}
char i = 255;
int sensorValue = 0;
unsigned char aa,bb;
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
unsigned char a = Serial.read();
if(a == 170)
{
delay(10);
aa = Serial.read();
delay(10);
bb = Serial.read();
}
}
sensorValue = analogRead(A0);
sensorValue = 1024 - sensorValue ;
sensorValue = sensorValue * 0.25;
if(aa == 0x01)
{
analogWrite(ledPin,sensorValue);
}
else
{
analogWrite(ledPin,255-bb);
}
Serial.write(0xaa);
Serial.write(0x01);
Serial.write(0x01);
Serial.write(sensorValue&0xff);
delay(100);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询