Étape 3: Code
Code du capteur de lumière : int CDSPin = 0 ; void setup() {} void loop() {}
int LEDPin = 13 ;
pinMode (LEDPin, sortie) ;
Serial.Begin(9600) ;
}
Éclairement int ;
Éclairement = analogRead(CDSPin) ;
Serial.println(lightLevel) ;
Delay(100) ;
Si (éclairement < 300)
{
digitalWrite (LEDPin, élevé) ;
}
ElseIf (éclairement > 300)
{digitalWrite (LEDPin, basse) ;
}
}
Code de l’eau de sonde :
waterSensor int = 2 ; int ledPin = 13 ; int speakerPin = 9 ; int longueur = 15 ; le nombre de billets playTone Sub (ton int, int duration) {} void playNote (char Remarque, int duration) {} Jouez le ton correspondant au nom de la note void setup() {} void loop() {}
note de char [] = "gggefffd" ; un espace représente un repos
int bat [] = {}
1, 1, 1, 3, 1, 1, 1, 3,} ;
int tempo = 300 ;
pour (long j’ai = 0; i < durée * 1000L; i += ton * 2) {
digitalWrite (speakerPin, HIGH) ;
delayMicroseconds(tone) ;
digitalWrite (speakerPin, basse) ;
delayMicroseconds(tone) ;
}
}
char nom [] = {}
'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
les tons int [] = {}
1915, 1700, 1519, 1432, 1275, 1136, 1014, 956} ;
pour (int i = 0; i < 8; i ++) {}
Si (noms [i] == note) {}
playTone (tons [i], durée) ;
}
}
}
pinMode (ledPin, sortie) ;
Serial.Begin(9600) ;
pinMode (speakerPin, sortie) ;
}
int sensorData ;
sensorData = analogRead(waterSensor) ;
Serial.println(sensorData) ;
Si {(sensorData < 50)
playTone ('b', 100) ;
}
ElseIf (sensorData > 51) {}
;
}
}