0% found this document useful (0 votes)
0 views1 page

Art Game Codes

The document contains C++ code for an Arduino program that reads values from a light-dependent resistor (LDR) connected to pin A5. It plays a tone on pin A3 when the LDR value exceeds 200 and activates a buzzer on pin 2 when the value is below 1000. The program includes setup and loop functions for initializing pins and continuously reading sensor values with delays for performance improvement.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views1 page

Art Game Codes

The document contains C++ code for an Arduino program that reads values from a light-dependent resistor (LDR) connected to pin A5. It plays a tone on pin A3 when the LDR value exceeds 200 and activates a buzzer on pin 2 when the value is below 1000. The program includes setup and loop functions for initializing pins and continuously reading sensor values with delays for performance improvement.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

// C++ code

//
void setup()
{
pinMode(A5, INPUT);
pinMode(A3, OUTPUT);
}

void loop()
{
Serial.println(A5);
if (analogRead(A5) > 200) {
tone(A3, 523, 1000); // play tone 60 (C5 = 523 Hz)
}
delay(10); // Delay a little bit to improve simulation performance
}

___________________________________________________________________
_____________

int sensorPin = A5; // select the input pin for ldr


int sensorValue = 0; // variable to store the value coming from the
sensor

void setup() {
pinMode(A4, OUTPUT); //pin connected to the buzzer
Serial.begin(9600); //sets serial port for communication
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue); //prints the values coming from the sensor
on the screen

if(sensorValue < 1000) //setting a threshold value


digitalWrite(2,HIGH); //turn buzzer ON

else digitalWrite(2,LOW); //turn buzzer OFF

delay(100);
}

You might also like