Loading...
Vietnam Geography App
Loading...
Vietnam Geography App
Trải nghiệm điều khiển thiết bị bằng nút nhấn, biến trở và cảm biến! Bạn sẽ học cách tương tác với thế giới thực, tạo hiệu ứng thú vị và xây dựng hệ thống thông minh chỉ với vài dòng code.
/*
Button và LED Control
Sử dụng button để điều khiển LED
*/
int buttonPin = 2;
int ledPin = 13;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Sử dụng pull-up resistor
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) { // Button được nhấn (pull-up = LOW khi nhấn)
digitalWrite(ledPin, HIGH);
Serial.println("Button pressed - LED ON");
} else {
digitalWrite(ledPin, LOW);
Serial.println("Button released - LED OFF");
}
delay(50); // Debouncing delay
}
Tạo counter đếm số lần nhấn button và hiển thị trên Serial Monitor
Sử dụng potentiometer để điều chỉnh độ sáng LED
Volume control cho audio systems
Dimmer switch cho đèn LED
User interface controls
Sensor calibration systems
Interactive art installations