Ligne 390 : |
Ligne 390 : |
| | | |
| <nowiki>/* Photocell simple testing sketch. | | <nowiki>/* Photocell simple testing sketch. |
− | Connect one end of photocell to power, the other end to pin 2.
| + | Connectez une broche d'une Photo-résistance sur l'alimentation, l'autre broche sur la Pin/Broche 2. |
− | Then connect one end of a 0.1uF capacitor from pin 2 to ground
| + | Connectez ensuite une des broches d'une capacité de 0.1uF (micro-Farad) sur la Pin 2 et l'autre broche à la masse. |
− | For more information see www.ladyada.net/learn/sensors/cds.html */
| + | |
| + | Pour plus d'information: |
| + | * voir http://mchobby.be/wiki/index.php?title=Photo-r%C3%A9sistance (en FRANCAIS) |
| + | * voir http://www.ladyada.net/learn/sensors/cds.html (en anglais) |
| + | |
| + | */ |
| | | |
− | int photocellPin = 2; // the LDR and cap are connected to pin2 | + | int photocellPin = 2; // La photorésistance et capacité connectés sur pin 2 |
− | int photocellReading; // the digital reading | + | int photocellReading; // Lecture de la valeur Digitale |
− | int ledPin = 13; // you can just use the 'built in' LED | + | int ledPin = 13; // Vous pouvez vous contenter de la LED disponible sur la carte (Pin 13) |
| | | |
| void setup(void) { | | void setup(void) { |
− | // We'll send debugging information via the Serial monitor | + | // démarrons la connection série pour envoyer des message de debugging. |
| Serial.begin(9600); | | Serial.begin(9600); |
− | pinMode(ledPin, OUTPUT); // have an LED for output | + | pinMode(ledPin, OUTPUT); // Activer la LED en sortie |
| } | | } |
| | | |
| void loop(void) { | | void loop(void) { |
− | // read the resistor using the RCtime technique | + | // Lecture de la résistance en utilisant la technique dite RCTime (temps chargement d'un circuit RC) |
| photocellReading = RCtime(photocellPin); | | photocellReading = RCtime(photocellPin); |
| | | |
| if (photocellReading == 30000) { | | if (photocellReading == 30000) { |
− | // if we got 30000 that means we 'timed out' | + | // Si nous obtenons 30000 cela signifie que nous avons un 'timed out' |
− | Serial.println("Nothing connected!"); | + | Serial.println("Rien de raccorder!"); |
| } else { | | } else { |
− | Serial.print("RCtime reading = "); | + | Serial.print("Lecture RCtime = "); |
− | Serial.println(photocellReading); // the raw analog reading | + | Serial.println(photocellReading); // La valeur brute |
| | | |
− | // The brighter it is, the faster it blinks! | + | // Plus il fait lumineux et plus vite elle clignotera! |
| digitalWrite(ledPin, HIGH); | | digitalWrite(ledPin, HIGH); |
| delay(photocellReading); | | delay(photocellReading); |
Ligne 424 : |
Ligne 429 : |
| } | | } |
| | | |
− | // Uses a digital pin to measure a resistor (like an FSR or photocell!) | + | // Utilisation d'une broche digitale pour mesurer une résistance (comme un photo-résistance) |
− | // We do this by having the resistor feed current into a capacitor and | + | // Nous obtenons le résultat en utilisant la résistance pour limiter le courant qui "remplit"/charge |
− | // counting how long it takes to get to Vcc/2 (for most arduinos, thats 2.5V) | + | // une capacité et compter combien de temps il faut pour atteindre Vcc/2 |
| + | // Pour la pluslart des Arduino un entrée digitale est activée à 2.5V |
| + | // |
| int RCtime(int RCpin) { | | int RCtime(int RCpin) { |
− | int reading = 0; // start with 0 | + | int reading = 0; // Démarrer avec 0 |
| | | |
− | // set the pin to an output and pull to LOW (ground) | + | // Activer la broche en sortie et placer à LOW (masse) |
| pinMode(RCpin, OUTPUT); | | pinMode(RCpin, OUTPUT); |
| digitalWrite(RCpin, LOW); | | digitalWrite(RCpin, LOW); |
| | | |
− | // Now set the pin to an input and... | + | // Maintenant, placer la PIN en entrée et ... |
| pinMode(RCpin, INPUT); | | pinMode(RCpin, INPUT); |
− | while (digitalRead(RCpin) == LOW) { // count how long it takes to rise up to HIGH | + | while (digitalRead(RCpin) == LOW) { // compter le temps qu'il faut pour quelle passe à HIGH |
− | reading++; // increment to keep track of time | + | reading++; // l'incrémentation est proportionnelle au temps qui passe |
| | | |
| if (reading == 30000) { | | if (reading == 30000) { |
− | // if we got this far, the resistance is so high | + | // Si nous arrivons si loin, c'est que la résistance est beaucoup trop |
− | // its likely that nothing is connected! | + | // grande... comme si rien n'était connecté! |
− | break; // leave the loop | + | break; // Abandonner la boucle |
| } | | } |
| } | | } |
− | // OK either we maxed out at 30000 or hopefully got a reading, return the count | + | // OK, nous avons soit atteind le maximum de 30000 ou nous avons |
| + | // plus de chance et obtenu un vrai résultat. |
| + | // Il ne reste plus qu'a retourner la valeur. |
| | | |
| return reading; | | return reading; |