Hi everyone,
I'm currently following an ubiquitous computing course at my studie.
It's not really my thing, but i'm trying to make the best of it.
Anyways, i'm doing a little proof of concept with a piezo speaker, led light and light sensor. I would like to make de speaker play a little tune and de led to shine when the light sensor doesn't receive any light.
I came this far:
int speakerPin = 12;
int photocellPin = A0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int reading = analogRead(photocellPin);
int pitch = 780-reading;
if(pitch>10)
tone(speakerPin, pitch);
else
noTone(speakerPin);
int ledwaarde = map(reading,400,797,255,0);
ledwaarde = constrain (ledwaarde, 0, 255);
analogWrite(9,ledwaarde);
Serial.println( reading);
Serial.println( ledwaarde);
delay(100);
}
The picture shows how i set it all up.
But of course it doesn't work.
What am i doing wrong? Can anyone help with this?
'ledwaarde' means the value of the led light. It's dutch which is probably confusing.
And int reading and int pitch had something to do with the light sensor. In every room the amount of light is different. Therefor i'm reading the amount of light that comes into the sensor so it can calculate whenever it's dark or not.
I don't know the exact answer because someone helped me with it.
But maybe i just have to try a different tutorial.
No. The question(s) were "What is the value in ledwaarde?"
I don't know the exact answer because someone helped me with it.
But, you are printing two of the three values of interest to the serial port. Though, without identifiers, so which is which is a problem. What are you seeing in the Serial Monitor?