LDR with LED RGB + Speaker
Here is the entire code:
int valueLDR = 0;int freq = 0;
int ledRed = 9;
int ledGreen = 10;
int ledBlue = 11;
int speaker = 8;
void setup() {
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.printIn(valueLDR);
delay(10);
valueLDR = analogRead(pinLDR);
int Red = map(valueLDR,0,20,0,255);
int Green = map(valueLDR,0,20,255,0);
int Blue = map(valueLDR,0,20,0,128);
int freq = map(valueLDR,0,20,261,494);
analogWrite(ledRed,Red);
analogWrite(ledGreen,Green);
analogWrite(ledBlue,Blue);
tone(speaker,freq,10);
}
By: Juan Antonio Calvete and Joel PoderĂ³s.