Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <FDC2214.h>
  3. FDC2214 capsense(FDC2214_I2C_ADDR_0); // Use FDC2214_I2C_ADDR_1
  4.  
  5. // ###
  6. void setup() {
  7.  
  8.   // ### Start I2C
  9.   Wire.begin();
  10.   //Wire.setClock(40000L);
  11.  
  12.   // ### Start serial
  13.   Serial.begin(115200);
  14.   Serial.println("\nFDC2x1x test");
  15.  
  16.   // ### Start FDC
  17.   // Start FDC2212 with 2 channels init
  18.   //bool capOk = capsense.begin(0x3, 0x4, 0x5); //setup first two channels, autoscan with 2 channels, deglitch at 10MHz
  19.   // Start FDC2214 with 4 channels init
  20.   bool capOk = capsense.begin(0xF, 0x4, 0x5); //setup all four channels, autoscan with 2 channels, deglitch at 10MHz
  21.   if (capOk) Serial.println("Sensor OK");  
  22.   else Serial.println("Sensor Fail");  
  23.  
  24. }
  25.  
  26. // ### Tell aplication how many chanels will be smapled in main loop
  27. #define CHAN_COUNT 4
  28.  
  29. // ###
  30. void loop() {
  31.   unsigned long capa[CHAN_COUNT]; // variable to store data from FDC
  32.   for (int i = 0; i < CHAN_COUNT; i++){ // for each channel
  33.     // ### read 28bit data
  34.     capa[i]= capsense.getReading16(i); //Changed this to 16 for fdc2114  
  35.     // ### Transmit data to serial in simple format readable by SerialPlot application.
  36.     Serial.print(capa[i]);  
  37.     if (i < CHAN_COUNT-1) Serial.print(", ");
  38.     else Serial.println("");
  39.   }
  40.   // No point in sleeping
  41.   delay(100);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement