Complete the code to set the motor pin as an output.
const int motorPin = 9; void setup() { pinMode([1], OUTPUT); } void loop() { // Motor control code here }
You need to tell the Arduino that motorPin is an output pin using pinMode().
Complete the code to turn the motor ON by setting the pin HIGH.
const int motorPin = 9; void setup() { pinMode(motorPin, OUTPUT); } void loop() { digitalWrite(motorPin, [1]); delay(1000); digitalWrite(motorPin, LOW); delay(1000); }
To turn the motor ON, set the pin to HIGH using digitalWrite().
Fix the error in the code to correctly control the motor speed using PWM.
const int motorPin = 9; void setup() { pinMode(motorPin, OUTPUT); } void loop() { analogWrite(motorPin, [1]); delay(1000); }
Use analogWrite() with a value between 0 and 255 to control motor speed. 255 means full speed.
Fill both blanks to create a dictionary comprehension that maps motor speeds to their PWM values if speed is greater than 100.
int speeds[] = {50, 120, 200};
void setup() {
// This is a conceptual example, Arduino C++ does not support dictionary comprehensions
// Imagine a map: {speed: [1] for speed in speeds if speed [2] 100}
}
void loop() {}The comprehension maps each speed to speed * 2 only if the speed is greater than 100.
Fill all three blanks to create a function that sets motor speed only if the speed is within 0 to 255.
const int motorPin = 9; void setup() { pinMode(motorPin, OUTPUT); } void setMotorSpeed(int speed) { if (speed [1] 0 && speed [2] 255) { analogWrite(motorPin, [3]); } } void loop() { setMotorSpeed(200); }
The function checks if speed is between 0 and 255 inclusive, then writes the speed value to the motor pin.
