I'm new to programming but i want to make with arduino UNO, distance sensor HC-SRO4, photoresistor and two buzzers a project. I want from the buzzer to change sound depending of the distance in front of the device and the other buzzer to change sound depending of the light. I can't understand how to multitask with arduino. Can someone help me with this?
I wired everything correctly and this is my code.
int valuesv;
int analogsv = A0;
#define trigPin 10
#define echoPin 11
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
valuesv = analogRead(analogsv);
valuesv = map(valuesv, 0, 1023, 0, 255);
Serial.println(valuesv);
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
int thispitch = map(distance, 0, 200, 1093, 22);
int Pitch = map(valuesv, 0, 1023, 0, 255);
tone(12, thispitch);
tone(13, Pitch);
delay(500);
noTone(13);
noTone(12);
}