Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

introducing touchtest, driver for the prototype

- based on capsense.
- works with four channels.
  • Loading branch information...
commit aa3741e6cf22e2be5e20c167f11c744adb49cc92 1 parent 3e10828
@vishnubob authored
Showing with 97 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +96 −0 touchtest/touchtest.pde
View
1  .gitignore
@@ -0,0 +1 @@
+.*.swp
View
96 touchtest/touchtest.pde
@@ -0,0 +1,96 @@
+#include <CapSense.h>
+#include <string.h>
+
+class Average
+{
+public:
+ Average(uint8_t sz) :
+ _sz(sz), _idx(0)
+ {
+ _data = (long*)malloc(_sz * sizeof(long));
+ //bzero(_data, _sz * sizeof(long));
+ }
+
+ void push(long val)
+ {
+ _data[_idx] = val;
+ _idx = (_idx + 1) % _sz;
+ }
+
+ long pull()
+ {
+ long sum = 0;
+ for(uint8_t sum_idx = 0; sum_idx < _sz; ++sum_idx)
+ {
+ sum += _data[sum_idx];
+ }
+ return (sum / ((float)_sz));
+ }
+
+ void set(uint8_t offset)
+ {
+ _level = pull() + offset;
+ }
+
+ bool trigger()
+ {
+ return (pull() > _level);
+ }
+
+private:
+ uint8_t _sz;
+ uint8_t _idx;
+ long* _data;
+ long _level;
+};
+
+CapSense cs_4_8 = CapSense(4,8);
+Average avg_4_8 = Average(10);
+CapSense cs_4_9 = CapSense(4,9);
+Average avg_4_9 = Average(10);
+CapSense cs_4_10 = CapSense(4,10);
+Average avg_4_10 = Average(10);
+CapSense cs_4_11 = CapSense(4,11);
+Average avg_4_11 = Average(10);
+
+void sample()
+{
+ avg_4_8.push(cs_4_8.capSense(50));
+ avg_4_9.push(cs_4_9.capSense(50));
+ avg_4_10.push(cs_4_10.capSense(50));
+ avg_4_11.push(cs_4_11.capSense(50));
+}
+
+void setup()
+{
+ Serial.begin(9600);
+ for(uint8_t x = 0; x < 100; ++x)
+ {
+ sample();
+ }
+ avg_4_8.set(25);
+ avg_4_9.set(25);
+ avg_4_10.set(25);
+ avg_4_11.set(25);
+}
+
+void loop()
+{
+ sample();
+ if (avg_4_8.trigger())
+ {
+ Serial.println("up");
+ }
+ if (avg_4_9.trigger())
+ {
+ Serial.println("down");
+ }
+ if (avg_4_10.trigger())
+ {
+ Serial.println("left");
+ }
+ if (avg_4_11.trigger())
+ {
+ Serial.println("right");
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.