Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <CapacitiveSensor.h>
- #include <Adafruit_NeoPixel.h>
- /*
- CapitiveSense Library Demo Sketch
- Paul Badger 2008
- Uses a high value resistor e.g. 10M between send pin and receive pin
- Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
- Receive pin is the sensor pin - try different amounts of foil/metal on this pin
- */
- CapacitiveSensor cs_4_5 = CapacitiveSensor(4, 5); // 330-ohmn resistor between pins 4 & 5, pin 5 is sensor pin, add a wire and or foil if desired
- int treshold = 50000; // the minimum value for turning the LED on
- unsigned long prevMillis = 0;
- unsigned long seconde = 0;
- unsigned long prevMillis1 = 0;
- int touch = 0;
- int ledPin = 12; //WS2812 pin
- int touch1seconde = 0;
- //int i;
- // How many NeoPixels are attached to the Arduino?
- #define NUMPIXELS 96 // Popular NeoPixel ring size
- // When setting up the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. Note that for older NeoPixel
- // strips you might need to change the third parameter -- see the strandtest example for more information on possible values.
- Adafruit_NeoPixel pixels(NUMPIXELS, ledPin, NEO_GRB + NEO_KHZ800);
- void setup()
- {
- // cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
- Serial.begin(9600);
- pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
- }
- void loop()
- {
- long sensorValue = cs_4_5.capacitiveSensor(30);
- if ((millis() - prevMillis) > 1000)
- {
- seconde++;
- Serial.println(seconde);
- Serial.println((String) "touch : " + touch);
- prevMillis = millis();
- }
- if (sensorValue > treshold & touch == 0)
- {
- Serial.println((String) "toucher : " + sensorValue); // print sensor output 1
- touch++;
- }
- if (touch == 1)
- {
- // The first NeoPixel in a strand is #0, second is 1, all the way up
- // to the count of pixels minus one.
- for (int i = 0; i < NUMPIXELS; i++)
- { // For each pixel...
- // Here we're using a moderately bright green color:
- pixels.setPixelColor(i, pixels.Color(255, 255, 255));
- pixels.show(); // Send the updated pixel colors to the hardware.
- Serial.println((String) "i : " + i);
- }
- Serial.println("led touch 2 ON");
- seconde = 0;
- touch++;
- }
- if (sensorValue > treshold & touch == 2 & seconde != 0)
- {
- Serial.println((String) "toucher : " + sensorValue); // print sensor output 1
- touch++;
- }
- if (touch == 3)
- {
- // The first NeoPixel in a strand is #0, second is 1, all the way up
- // to the count of pixels minus one.
- for (int i = 0; i < NUMPIXELS; i++)
- { // For each pixel...
- // Here we're using a moderately bright green color:
- pixels.setPixelColor(i, pixels.Color(0, 255, 0));
- pixels.show(); // Send the updated pixel colors to the hardware.
- }
- Serial.println("led touch 3 ON");
- seconde = 0;
- touch++;
- }
- if (sensorValue > treshold & touch == 4 & seconde != 0)
- {
- Serial.println((String) "toucher : " + sensorValue); // print sensor output 1
- touch++;
- }
- if (touch == 5)
- {
- // The first NeoPixel in a strand is #0, second is 1, all the way up
- // to the count of pixels minus one.
- for (int i = 0; i < NUMPIXELS; i++)
- { // For each pixel...
- // Here we're using a moderately bright green color:
- pixels.setPixelColor(i, pixels.Color(255, 60, 5));
- pixels.show(); // Send the updated pixel colors to the hardware.
- }
- Serial.println("led touch 3 ON");
- seconde = 0;
- touch++;
- }
- if (sensorValue > treshold & touch == 6 & seconde != 0)
- {
- Serial.println((String) "toucher : " + sensorValue); // print sensor output 1
- touch++;
- }
- if (touch == 7)
- {
- for (int i = 0; i < NUMPIXELS; i++)
- { // For each pixel...
- pixels.clear(); // Set all pixel colors to 'off'
- pixels.show(); // Send the updated pixel colors to the hardware.
- }
- seconde = 0;
- touch = 0;
- Serial.println("led OFF");
- }
- if (seconde > 600)
- {
- for (int i = 0; i < NUMPIXELS; i++)
- { // For each pixel...
- pixels.clear(); // Set all pixel colors to 'off'
- pixels.show(); // Send the updated pixel colors to the hardware.
- }
- seconde = 0;
- touch = 0;
- Serial.println("led OFF");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement