-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouch.ino
95 lines (85 loc) · 2.67 KB
/
touch.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <defs.h>
#include <mpr121.h>
#include <i2c_touch_sensor.h>
#include <Adafruit_MPR121.h>
#include <i2c_touch_sensor.h>
#include <ChainableLED.h>
#define NUM_LEDS 1
ChainableLED leds(19, 18, NUM_LEDS);
/* GroveI2CTouchTest.pde - Sample code for the SeeedStudio Grove I2C Touch Sensor
http://seeedstudio.com/wiki/index.php?title=Twig_-_I2C_Touch_Sensor_v0.93b
Prerequisite: A modification of the Grove I2C Touch sensor is needed Solder a pin to
the INT terminal in the I2C sensor to connect it to one pin in Arduino Created by
Wendell A. Capili, August 27, 2011. http://wendellinfinity.wordpress.com
Released into the public domain.*/
#include <Wire.h>
i2ctouchsensor touchsensor;
long previousMillis = 0;
long interval = 100;
void setup()
{ leds.init();
Serial.begin(9600); // for debugging
Serial.print("begin to init");
Wire.begin(); // needed by the GroveMultiTouch lib
touchsensor.initialize(); // initialize the feelers // initialize the containers
//for(int i=0; i<=3; i++)
//{
// padTouched[i]=false;
//}
}
float hue = 0.0;
boolean up = true;
void loop()
{
unsigned char MPR_Query=0;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
touchsensor.getTouchState();
}
for (int i=0;i<12;i++)
{
if (touchsensor.touched&(1<<i))
{
Serial.print("pin ");
Serial.print(i);
Serial.println(" was touched");
if (i == 0){
leds.setColorHSL(i, hue, 1.0, 0.5);
}
else if (i == 1){
leds.setColorHSL(i, hue, 1.5, 0.5);
}
}
}
}
/*
touchsensor.readTouchInputs(); // test read the touch sensors
// loop through our touch sensors 1 to 4
for(int i=0; i<=3; i++)
{
// get the touch state based on pin #
if(feelers.getTouchState(i))
{
if(!padTouched[i])
{ // print in serial that it was touched
Serial.print("Pad ");
Serial.print(i);
Serial.println(" was touched");
}
// flag the touch sensor state
padTouched[i]=true;
}
else
{
if(padTouched[i])
{
// print in serial that it was released
Serial.print("Pad ");
Serial.print(i);
Serial.println(" was released");
} // reset the touch sensor state
padTouched[i]=false;
}
}*/