Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
wiki:tutoriels:arduino-capteurs:arduino-capteurs [2022/05/09 15:55] damien.muti [Capteur capacitif interne à la carte Arduino] |
wiki:tutoriels:arduino-capteurs:arduino-capteurs [2022/06/22 15:12] (Version actuelle) damien.muti [Allumer aléatoirement une chaine de LED] |
||
---|---|---|---|
Ligne 898: | Ligne 898: | ||
- | | + | //Import a library from the Arduino folder |
- | #include < | + | #include < |
- | //Select the two pins that will act as a capacitor | + | //Select the two pins that will act as a capacitor |
- | CapacitiveSensor capSensor = CapacitiveSensor(4, | + | CapacitiveSensor capSensor = CapacitiveSensor(4, |
- | //Insert the minimum value provided by the sensor to detect the touch | + | //Insert the minimum value provided by the sensor to detect the touch |
- | int threshold = 1000; | + | int threshold = 1000; |
- | const int ledPin = 12; | + | const int ledPin = 12; |
- | | + | void setup() { |
- | Serial.begin(9600); | + | Serial.begin(9600); |
- | pinMode(ledPin, | + | pinMode(ledPin, |
- | } | + | } |
- | | + | void loop() { |
- | //Read the sensor value | + | //Read the sensor value |
- | long sensorValue = capSensor.capacitiveSensor(30); | + | long sensorValue = capSensor.capacitiveSensor(30); |
- | Serial.println(sensorValue); | + | Serial.println(sensorValue); |
- | //Touch detected | + | //Touch detected |
- | if (sensorValue > threshold) { | + | if (sensorValue > threshold) { |
//Turn on the led | //Turn on the led | ||
digitalWrite(ledPin, | digitalWrite(ledPin, | ||
- | | + | |
- | //Touch undetected | + | //Touch undetected |
- | else { | + | else { |
//Turn off the led | //Turn off the led | ||
digitalWrite(ledPin, | digitalWrite(ledPin, | ||
- | | + | |
- | delay(10); | + | delay(10); |
- | } | + | } |
Ligne 1331: | Ligne 1331: | ||
Une autre version : {{ : | Une autre version : {{ : | ||
+ | |||
+ | === Références === | ||
+ | * https:// | ||
---- | ---- |