Modifications

Sauter à la navigation Sauter à la recherche
2 087 octets ajoutés ,  23 juillet 2012 à 16:56
Ligne 308 : Ligne 308 :  
Dans ce cas, notre 'seau' est une capacité céramique de 0.1uF. Vous pouvez pratiquement utiliser n'importe quelle capacité mais cela affectera le temps de chargement.<br />
 
Dans ce cas, notre 'seau' est une capacité céramique de 0.1uF. Vous pouvez pratiquement utiliser n'importe quelle capacité mais cela affectera le temps de chargement.<br />
 
0.1uF semble être une valeur de départ idéal pour les senseurs FSR.
 
0.1uF semble être une valeur de départ idéal pour les senseurs FSR.
 +
 +
<nowiki>
 +
    /* FSR simple testing sketch.
 +
    Connect one end of FSR to power, the other end to pin 2.
 +
    Then connect one end of a 0.1uF capacitor from pin 2 to ground
 +
    For more information see www.ladyada.net/learn/sensors/fsr.html */
 +
    int fsrPin = 2; // the FSR and cap are connected to pin2
 +
    int fsrReading; // the digital reading
 +
    int ledPin = 13; // you can just use the 'built in' LED
 +
    void setup(void) {
 +
    // We'll send debugging information via the Serial monitor
 +
    Serial.begin(9600);
 +
    pinMode(ledPin, OUTPUT); // have an LED for output
 +
    }
 +
    void loop(void) {
 +
    // read the resistor using the RCtime technique
 +
    fsrReading = RCtime(fsrPin);
 +
    if (fsrReading == 30000) {
 +
    // if we got 30000 that means we 'timed out'
 +
    Serial.println("Nothing connected!");
 +
    } else {
 +
    Serial.print("RCtime reading = ");
 +
    Serial.println(fsrReading); // the raw analog reading
 +
    // Do a little processing to keep the LED blinking
 +
    fsrReading /= 10;
 +
    // The more you press, the faster it blinks!
 +
    digitalWrite(ledPin, HIGH);
 +
    delay(fsrReading);
 +
    digitalWrite(ledPin, LOW);
 +
    delay(fsrReading);
 +
    }
 +
    delay(100);
 +
    }
 +
    // Uses a digital pin to measure a resistor (like an FSR or photocell!)
 +
    // We do this by having the resistor feed current into a capacitor and
 +
    // counting how long it takes to get to Vcc/2 (for most arduinos, thats 2.5V)
 +
    int RCtime(int RCpin) {
 +
    int reading = 0; // start with 0
 +
    // set the pin to an output and pull to LOW (ground)
 +
    pinMode(RCpin, OUTPUT);
 +
    digitalWrite(RCpin, LOW);
 +
    // Now set the pin to an input and...
 +
    pinMode(RCpin, INPUT);
 +
    while (digitalRead(RCpin) == LOW) { // count how long it takes to rise up to HIGH
 +
    reading++; // increment to keep track of time
 +
    if (reading == 30000) {
 +
    // if we got this far, the resistance is so high
 +
    // its likely that nothing is connected!
 +
    break; // leave the loop
 +
    }
 +
    }
 +
    // OK either we maxed out at 30000 or hopefully got a reading, return the count
 +
    return reading;
 +
    }
 +
 +
</nowiki>
    
== Source ==
 
== Source ==
29 917

modifications

Menu de navigation