ok so i need to do a combination of 3 circuits on the arduino uno. i decided to do led, buzzer, and a photo resister/light sensor controlling the brightness of a different led.
so heres my code:
const int sensorPin = 0;
const int ledPin = 10;
int buzzer = 8;
int led = 9;
int lightLevel, high = 0, low = 1023;
void setup()
{
pinMode (buzzer, OUTPUT);
pinMode(led, OUTPUT);
pinMode (ledPin, OUTPUT);
}
void loop()
loop()
{
{ {
tone(buzzer, 262, 900);
delay(1000);
digitalWrite(led, HIGH);
tone(buzzer, 700, 900);
delay(1000);
digitalWrite(led, LOW );
tone(buzzer, 262, 900);
delay(1000);
digitalWrite(led, HIGH);
tone(buzzer, 400, 900);
delay(1000);
digitalWrite(led, LOW);
}
}
{
lightLevel = analogRead(sensorPin);
manualTune();
analogWrite(ledPin, lightLevel);
}
void manualTune()
{
lightLevel = map(lightLevel, 0, 1023, 0, 255);
lightLevel = constrain(lightLevel, 0, 255);
}
void autoTune()
{
if (lightLevel < low)
{
low = lightLevel;
}
if (lightLevel > high)
{
high = lightLevel;
}
lightLevel = map(lightLevel, low+30, high-30, 0, 255);
lightLevel = constrain(lightLevel, 0, 255);
}
dould you guys please fix it up and write a code that works. btw ledPin is the one tha will be getting dimmer and brightter and led is the one that will be blinking to the beat of the buzzer.
thanks guys
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.