Homework Week5_Qianjing_Liu

IMG_0944 IMG_0949 IMG_0951 IMG_0956


This is a clock. When the sun light came into the small house from the break on the roof, the clock inside will make sound and weak up users. There is also a switch on the house, which can control the sound value and turn off the clock.


#include “pitches.h”

int speaker = 11;
int sensor1 = A0;
int sensor2 = A1;
int sensorValue = 0;
int getsensor2 = 0;
int getsensor1 = 0;

void setup() {
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
pinMode(speaker, OUTPUT);

void loop() {
getsensor1 = analogRead(sensor1);
getsensor2 = analogRead(sensor2);
sensorValue = map(getsensor2, 0, 1023, 0, 4000);
if(getsensor1<=0 || getsensor2<=0){
digitalWrite(speaker, LOW);
tone(speaker, sensorValue);

Leave a Reply

Your email address will not be published.