void setup() {
Serial.begin(115200);
Serial.println("Practical Test 1: Short Questions (Friday)");
Serial.println(" 1. Press the button to turn OFF the blue LED");
Serial.println(" 2. Periodically print the raw value of the potential meter");
Serial.println(" 3. If the raw count <2000, turn ON the red LED");
pinMode(32, INPUT_PULLUP); // Button
pinMode(14, INPUT); // Blue LED
pinMode(23, OUTPUT); // Red LED
pinMode(19, OUTPUT); // Potentiometer
}
void loop() {
// 1. Button control for blue LED
int buttonState = digitalRead(32);
if (buttonState == LOW) { // Button is pressed (active low due to pull-up)
digitalWrite(23, LOW); // Turn off blue LED
} else {
digitalWrite(23, HIGH); // Turn on blue LED when button is not pressed
}
// 2. Read and print potentiometer value periodically
int potValue = analogRead(14);
static unsigned long lastPrintTime = 0;
if (millis() - lastPrintTime >= 500) { // Print every 500ms
Serial.print("Potentiometer raw value: ");
Serial.println(potValue);
lastPrintTime = millis();
}
// 3. Control red LED based on potentiometer value (<2000)
if (potValue < 2000) {
digitalWrite(19, HIGH); // Turn ON red LED
} else {
digitalWrite(19, LOW); // Turn OFF red LED
}
delay(500); // Print and check every 500ms
}
Practical Test 1: Short Question (Friday)
1. Press the button to turn OFF the blue LED
2. Periodically print the raw count of the potential meter
3. If the raw count<2000, turn ON the red LED