PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

40 lines
1.7KB

  1. #include <CapacitiveSensor.h>
  2. /*
  3. * CapitiveSense Library Demo Sketch
  4. * Paul Badger 2008
  5. * Uses a high value resistor e.g. 10M between send pin and receive pin
  6. * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
  7. * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
  8. */
  9. CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
  10. CapacitiveSensor cs_4_6 = CapacitiveSensor(4,6); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
  11. CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
  12. void setup()
  13. {
  14. cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
  15. Serial.begin(9600);
  16. }
  17. void loop()
  18. {
  19. long start = millis();
  20. long total1 = cs_4_2.capacitiveSensor(30);
  21. long total2 = cs_4_6.capacitiveSensor(30);
  22. long total3 = cs_4_8.capacitiveSensor(30);
  23. Serial.print(millis() - start); // check on performance in milliseconds
  24. Serial.print("\t"); // tab character for debug windown spacing
  25. Serial.print(total1); // print sensor output 1
  26. Serial.print("\t");
  27. Serial.print(total2); // print sensor output 2
  28. Serial.print("\t");
  29. Serial.println(total3); // print sensor output 3
  30. delay(10); // arbitrary delay to limit data to serial port
  31. }