Alarm Clock Using Arduino

8 ビュー (過去 30 日間)
Anna Paul
Anna Paul 2020 年 4 月 25 日
回答済み: Rutuja 2025 年 9 月 15 日
Design an alarm with two pushbuttons, a photoresistor, and a buzzer. Have one push-button act a snooze for 4 seconds and the other to turn off the buzzer.
My Photoresistor is attached to Analog Pin (A1), the Piezo/buzzer is attached to (PWM pin3), Pushbutton one is attached to digital pin(7), and the second buzzer is attached to digital pin (8).
MY CODE: I have the photoresistor figured out, just need help with the two push buttons. Please Help!
clear; clc;
a= arduino();
count= 0;% staring button % Snooze = 0; %inital state
Snooze=0
Off= 0;%inital state
while true
v = readVoltage(a,'A1');%photoresistor
disp(v);
if v >= 4
playTone(a,'D3',290,'on');%buzzer
end
Snooze = readDigitalPin(a,'D8'); %snooze 5 sec
if Snooze == 1 && Off == 0
playTone (a,'D3',290,0.5);
end
end

回答 (2 件)

colordepth
colordepth 2025 年 3 月 10 日
編集済み: colordepth 2025 年 3 月 10 日
For the snooze button, check if it is pressed and use the "pause" function to delay the buzzer for 4 seconds. For the off button, set a flag when it is pressed to stop the buzzer. Use this flag in your loop to decide whether the buzzer should sound. You can find the documentation for the "pause" function here: https://www.mathworks.com/help/matlab/ref/pause.html.

Rutuja
Rutuja 2025 年 9 月 15 日

MATLAB Answers

Alarm Clock Using Arduino 3 views (last 30 days) Anna Paul Anna Paul on 25 Apr 2020 ⋮ Edited: colordepth on 10 Mar 2025 Design an alarm with two pushbuttons, a photoresistor, and a buzzer. Have one push-button act a snooze for 4 seconds and the other to turn off the buzzer. My Photoresistor is attached to Analog Pin (A1), the Piezo/buzzer is attached to (PWM pin3), Pushbutton one is attached to digital pin(7), and the second buzzer is attached to digital pin (8). MY CODE: I have the photoresistor figured out, just need help with the two push buttons. Please Help! clear; clc; a= arduino(); count= 0;% staring button % Snooze = 0; %inital state Snooze=0 Off= 0;%inital state while true v = readVoltage(a,'A1');%photoresistor disp(v); if v >= 4 playTone(a,'D3',290,'on');%buzzer end Snooze = readDigitalPin(a,'D8'); %snooze 5 sec if Snooze == 1 && Off == 0 playTone (a,'D3',290,0.5); end

end

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by