-Programa usado: Arduino.
- Código fonte:
int LDR; //declara variável
float VLDR;
int ledPin=13;
int ledPin1=12;
int ledPin2=3;
int ledPin3=2;
void setup(){
Serial.begin(9600);
pinMode(A0, INPUT);// entrada A0
pinMode(13,OUTPUT); // define o pino 13 como saida
pinMode(12,OUTPUT);
pinMode(3,OUTPUT);
pinMode(2,OUTPUT);
pinMode(9,OUTPUT); }
void loop(){
LDR = analogRead(A0);
VLDR=LDR*5.0000000/1024;
Serial.print(LDR);
Serial.print(" ");
Serial.print(VLDR);
Serial.println ( "\t");
delay(2);
if (LDR > 300 && LDR<325) {
tone(9,261.6,100);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
if (LDR > 330 && LDR < 375) {
tone(9,293.7,100);
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
if (LDR > 380 && LDR < 460 ) {
tone(9,329.6,100);
digitalWrite(12, LOW);
digitalWrite(3, HIGH);
digitalWrite(13, LOW);
digitalWrite(2, LOW);
}
if (LDR > 490 && LDR < 540 ) {
tone(9,349.2,100);
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
}
if (LDR > 570) {
tone(9,392.0,100);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
}
//toque a freqüência de 440 Hz (função tone no pino 9, com duração)
if (LDR < 290){
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
noTone(9);
}
//e não toque nada 9 noTone no pino 9; }
}