1
2
3
4
5
6
7
8
9
10
11
12#include <Adafruit_NeoPixel.h>
13#include <CapacitiveSensor.h>
14#define PIN 10
15#define LEDS 1
16
17int DELAY_TIME = 500;
18int COUNTER = 0;
19boolean LIGHT_STATE = false;
20
21Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN ,NEO_GRB + NEO_KHZ800);
22CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2);
23
24void setup() {
25
26 Serial.begin(9600);
27
28 cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
29 Serial.begin(9600);
30
31 strip.begin();
32 strip.show();
33 strip.setPixelColor(0, 69, 255, 0);
34 strip.show();
35
36}
37
38void loop() {
39
40 long total1 = cs_4_2.capacitiveSensor(30);
41
42 if(total1>400)
43 {
44 COUNTER++ ;
45 }
46
47 else
48 {
49 COUNTER = 0;
50 }
51
52if((total1>400) && (!LIGHT_STATE))
53{
54 strip.setPixelColor(0, 69, 255, 0);
55 strip.show();
56 delay(400);
57 LIGHT_STATE = true;
58}
59
60total1 = cs_4_2.capacitiveSensor(30);
61
62if((total1>400) && (LIGHT_STATE))
63{
64
65 strip.setPixelColor(0, 0, 0, 0);
66 strip.show();
67 delay(400);
68 LIGHT_STATE = false;
69}
70
71while(COUNTER>3)
72{
73
74 strip.setPixelColor(0, 255, 0, 0);
75 strip.show();
76 delay(DELAY_TIME);
77
78total1 = cs_4_2.capacitiveSensor(30);
79
80if(total1<400)
81{
82 break;
83}
84
85 strip.setPixelColor(0,0, 255, 0);
86 strip.show();
87 delay(DELAY_TIME);
88
89total1 = cs_4_2.capacitiveSensor(30);
90
91if(total1<400)
92{
93 break;
94}
95
96 strip.setPixelColor(0, 0, 0, 255);
97 strip.show();
98 delay(DELAY_TIME);
99
100total1 = cs_4_2.capacitiveSensor(30);
101
102if(total1<400)
103{
104 break;
105}
106
107 strip.setPixelColor(0, 69, 255, 0);
108 strip.show();
109 delay(DELAY_TIME);
110
111total1 = cs_4_2.capacitiveSensor(30);
112
113if(total1<400)
114{
115 break;
116}
117
118 strip.setPixelColor(0, 255, 255, 10);
119 strip.show();
120 delay(DELAY_TIME);
121
122total1 = cs_4_2.capacitiveSensor(30);
123
124if(total1<400)
125{
126 break;
127}
128
129
130strip.setPixelColor(0, 69, 139, 19);
131 strip.show();
132 delay(DELAY_TIME);
133
134total1 = cs_4_2.capacitiveSensor(30);
135
136if(total1<400)
137{
138 break;
139}
140
141 strip.setPixelColor(0, 0, 139, 139);
142 strip.show();
143 delay(DELAY_TIME);
144
145
146total1 = cs_4_2.capacitiveSensor(30);
147
148if(total1<400)
149{
150 break;
151}
152
153
154
155 strip.setPixelColor(0, 165, 218, 32);
156 strip.show();
157 delay(DELAY_TIME);
158
159total1 = cs_4_2.capacitiveSensor(30);
160
161if(total1<400)
162{
163 break;
164}
165
166
167}
168
169}
170
171
172
173
174
175
176
177
178
179
180
181
182