A student is writing a program to control a smart fan. The program is designed to start the motor automatically when the ambient light sensor detects that a lamp in the room has been turned on. In the context of event-driven programming, what is the most appropriate term for the specific block of code that contains the instructions to start the motor?
高中 (HKDSE) · 資訊及通訊科技
程式編寫在現實生活的應用:练习题
5 道选择题即时批改,另有 5 道文字题附完整解题步骤,全部围绕「程式編寫在現實生活的應用」。
In an event-driven program for a robotic arm, the system needs to respond to various inputs. Which of the following scenarios describes a sensor-based event rather than a user-action event?
When constructing a program that uses speech recognition to control a motor, why is it often necessary to implement asynchronous event handling rather than simple sequential polling of the audio input?
When developing a program to interact with specialized physical hardware such as an accelerometer or a speech recognition module, what is the primary advantage of using extended programming modules or libraries?
A student is developing a program for an automated greenhouse. The program must monitor the ambient brightness and trigger a motor to close the blinds when the light level exceeds a specific value. Which component of event-driven programming is primarily responsible for executing the code to close the blinds when this light threshold is reached?
A student is developing an event-driven program for an automatic street lighting system. Describe the event that would trigger the system to turn the lights on and name one physical output device that the program would control.
先自己写一遍答案,再对照解题步骤。
A high-tech fitness watch uses a built-in accelerometer and a vibration motor to assist users in maintaining a proper running pace. Describe the logical flow of an event-driven program for this device that triggers a tactile alert when the user's sudden acceleration exceeds a pre-defined threshold, and specify which component acts as the event source.
先自己写一遍答案,再对照解题步骤。
Consider a smart doorbell system designed to take a photo when motion is detected. Explain how an event handler would be structured to manage this functionality, identifying the specific event and the corresponding action.
先自己写一遍答案,再对照解题步骤。
A logistics company is developing an automated parcel sorting system that uses a robotic arm controlled by a microcontroller. The system includes a weight sensor, an accelerometer to detect if the platform is unstable, and servo motors to move parcels into different bins.
(a) Explain the difference between using a polling method and an event-driven method to monitor the accelerometer for instability. State one advantage of the event-driven approach in this real-life application.
(b) The developers use an extended programming library to control the motors. Describe two benefits of using such a library instead of writing low-level code to communicate with the hardware.
(c) The sorting logic is defined as follows:
- If the accelerometer detects a tilt where the vertical acceleration falls below a threshold, i.e., \( a_z < 9.0 \) \( m/s^2 \), the system must immediately call a function EmergencyStop().
- Otherwise, it reads the weight \( W \). If \( W \ge 5 \) kg, it triggers MoveArm(Bin_A). If \( 0.5 \le W < 5 \) kg, it triggers MoveArm(Bin_B). If \( W < 0.5 \) kg, the parcel is ignored.
Write a pseudocode segment for the event handler onWeightChange(W, az) that implements this logic.
先自己写一遍答案,再对照解题步骤。
A logistics warehouse uses a fleet of automated guided vehicles (AGVs) to transport goods. Each AGV is equipped with an accelerometer and a motor controller. The AGV program must automatically stop the motor if the vehicle detects a sudden impact or tilt beyond a safe threshold to prevent damage.
(a) Explain how the accelerometer acts as an input device for this real-life application and describe the specific type of data it would capture for the program.
(b) In the context of event-driven programming, identify the 'event' that would trigger the emergency stop and explain how an event handler would be used to manage this situation.
(c) The development team decides to use an extended programming module to interface with the AGV's hardware. State two advantages of using such a module instead of writing the hardware-level communication code from scratch.
(d) Suggest another physical device that could be integrated into the system using a similar programming approach to help the AGV avoid obstacles, and name the corresponding physical output action the program should perform when an obstacle is detected.
先自己写一遍答案,再对照解题步骤。
* thinka 提供的内容由 AI 生成,未必在任何情况下都完全准确或最新,请结合官方教材与教师指导使用。
想多做几道同类题目?立即开始练习这个课题,边做边批改。
立即练习