Example Code for Arduino-Button Control LED Flashing
Last revision 2025/12/26
Press buttons of S1 to S2, different frequencies of the LED flashing will be seen. This is because different resistances are built in, leading to different voltage dispatched to the analog ports. So do the data acquired by AD.
Hardware Preparation
Software Preparation
- Download Arduino IDE: Click to download Arduino IDE
Other Preparation Work
RoMeo BLE integrated 5 buttons, S1 to S5, which are controlled by Anolog Port 7. Switch it on as shown in the following figure when using analog buttons.
Sample Code
int potPin = 7;
int ledPin = 13;
int val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
val = analogRead(potPin);
digitalWrite(ledPin, HIGH); // Open the LED.
delay(val);
digitalWrite(ledPin, LOW); // Close the LED.
delay(val);
}
Result
Different frequencies of the LED flashing will be seen when pressing buttons of S1 to S2.
Was this article helpful?
