:D 获取中...

1 Variables && Built-in Functions

const int ledPin =  13;  
int ledState = LOW;             // led状态,亮或者灭,可以修改
long previousMillis = 0;        // 存储最后一次的led状态
unsigned long currentMillis = millis();
int ledPins[] = { 
  0,1,2, 3, 4, 5, 6, 7, };   // 对应的led引脚
  
pinMode(LED, OUTPUT);
pinMode(pushButton, INPUT); // 独立模块LY-51S开发板上独立按键K1-K8都可以使用。
digitalWrite(LED, HIGH); 
// 初始化串口
Serial.begin(9600);
//这里可以使用arduino自带的串口调试器,也可以使用德飞莱串口调试软件
  Serial.println(buttonState);
  
// if else
    if (ledState == LOW){
      ledState = HIGH;
    }else{
      ledState = LOW;
    }
// for
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT); 
  }
// 读取电位器的值
  int sensorReading = analogRead(analogPin);
// 把对应的值转化成0-最大led个数,这里是8
  int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
  • 共阳模式地电位点亮,共阴模式高电位点亮。

2 Main Part

2.1 Setup

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

2.2 Loop

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}