CSI012_Arduino_QA_Complete
CSI012_Arduino_QA_Complete
A sketch is a program written using the Arduino IDE, consisting of a setup() and loop() function. It is uploaded
Comments are lines ignored by the compiler, used to document code and improve readability.
void loop() {
Analog in pins (A0-A5) read variable voltages using ADC, returning values from 0-1023.
Excessive use blocks code execution, making Arduino unresponsive. Prefer millis() for non-blocking timing.
while (analogRead(A0) < 600) { delay(200); } // waits until sensor exceeds 600
Q7(a). Potentiometer with analogRead():
analogWrite(9, brightness);
previousTime = millis();
ledState = !ledState;
digitalWrite(13, ledState);
for (int i = 0; i < 10; i++) { digitalWrite(ledPin, HIGH); delay(100); digitalWrite(ledPin, LOW); }
PWM simulates analog output via digital pulses; analogWrite() generates PWM using 0-255 values.
if (Serial.available()) {
char c = Serial.read();
if (c == 'L') servo.write(0);