Advertisement
Justinberger

Lampe.ino

Jan 14th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.42 KB | None | 0 0
  1. #include <CapacitiveSensor.h>
  2. #include <Adafruit_NeoPixel.h>
  3. /*
  4.   CapitiveSense Library Demo Sketch
  5.   Paul Badger 2008
  6.   Uses a high value resistor e.g. 10M between send pin and receive pin
  7.   Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
  8.   Receive pin is the sensor pin - try different amounts of foil/metal on this pin
  9. */
  10. 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
  11. int treshold = 50000;                             // the minimum value for turning the LED on
  12. unsigned long prevMillis = 0;
  13. unsigned long seconde = 0;
  14. unsigned long prevMillis1 = 0;
  15. int touch = 0;
  16. int ledPin = 12; //WS2812 pin
  17. int touch1seconde = 0;
  18. //int i;
  19.  
  20. // How many NeoPixels are attached to the Arduino?
  21. #define NUMPIXELS 96 // Popular NeoPixel ring size
  22.  
  23. // 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
  24. // strips you might need to change the third parameter -- see the strandtest example for more information on possible values.
  25. Adafruit_NeoPixel pixels(NUMPIXELS, ledPin, NEO_GRB + NEO_KHZ800);
  26.  
  27. void setup()
  28. {
  29.   //  cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
  30.   Serial.begin(9600);
  31.   pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  32. }
  33.  
  34. void loop()
  35. {
  36.   long sensorValue = cs_4_5.capacitiveSensor(30);
  37.  
  38.   if ((millis() - prevMillis) > 1000)
  39.   {
  40.     seconde++;
  41.     Serial.println(seconde);
  42.     Serial.println((String) "touch : " + touch);
  43.     prevMillis = millis();
  44.   }
  45.  
  46.   if (sensorValue > treshold & touch == 0)
  47.   {
  48.     Serial.println((String) "toucher : " + sensorValue); // print sensor output 1
  49.     touch++;
  50.   }
  51.   if (touch == 1)
  52.   {
  53.     // The first NeoPixel in a strand is #0, second is 1, all the way up
  54.     // to the count of pixels minus one.
  55.     for (int i = 0; i < NUMPIXELS; i++)
  56.     { // For each pixel...
  57.       // Here we're using a moderately bright green color:
  58.       pixels.setPixelColor(i, pixels.Color(255, 255, 255));
  59.       pixels.show(); // Send the updated pixel colors to the hardware.
  60.       Serial.println((String) "i : " + i);
  61.     }
  62.     Serial.println("led touch 2 ON");
  63.     seconde = 0;
  64.     touch++;
  65.   }
  66.  
  67.   if (sensorValue > treshold & touch == 2 & seconde != 0)
  68.   {
  69.     Serial.println((String) "toucher : " + sensorValue); // print sensor output 1
  70.     touch++;
  71.   }
  72.  
  73.   if (touch == 3)
  74.   {
  75.     // The first NeoPixel in a strand is #0, second is 1, all the way up
  76.     // to the count of pixels minus one.
  77.     for (int i = 0; i < NUMPIXELS; i++)
  78.     { // For each pixel...
  79.       // Here we're using a moderately bright green color:
  80.       pixels.setPixelColor(i, pixels.Color(0, 255, 0));
  81.       pixels.show(); // Send the updated pixel colors to the hardware.
  82.     }
  83.     Serial.println("led touch 3 ON");
  84.     seconde = 0;
  85.     touch++;
  86.   }
  87.  
  88.   if (sensorValue > treshold & touch == 4 & seconde != 0)
  89.   {
  90.     Serial.println((String) "toucher : " + sensorValue); // print sensor output 1
  91.     touch++;
  92.   }
  93.  
  94.   if (touch == 5)
  95.   {
  96.     // The first NeoPixel in a strand is #0, second is 1, all the way up
  97.     // to the count of pixels minus one.
  98.     for (int i = 0; i < NUMPIXELS; i++)
  99.     { // For each pixel...
  100.       // Here we're using a moderately bright green color:
  101.       pixels.setPixelColor(i, pixels.Color(255, 60, 5));
  102.       pixels.show(); // Send the updated pixel colors to the hardware.
  103.     }
  104.     Serial.println("led touch 3 ON");
  105.     seconde = 0;
  106.     touch++;
  107.   }
  108.   if (sensorValue > treshold & touch == 6 & seconde != 0)
  109.   {
  110.     Serial.println((String) "toucher : " + sensorValue); // print sensor output 1
  111.     touch++;
  112.   }
  113.  
  114.   if (touch == 7)
  115.   {
  116.     for (int i = 0; i < NUMPIXELS; i++)
  117.     {                 // For each pixel...
  118.       pixels.clear(); // Set all pixel colors to 'off'
  119.       pixels.show();  // Send the updated pixel colors to the hardware.
  120.     }
  121.     seconde = 0;
  122.     touch = 0;
  123.     Serial.println("led OFF");
  124.   }
  125.  
  126.   if (seconde > 600)
  127.   {
  128.     for (int i = 0; i < NUMPIXELS; i++)
  129.     {                 // For each pixel...
  130.       pixels.clear(); // Set all pixel colors to 'off'
  131.       pixels.show();  // Send the updated pixel colors to the hardware.
  132.     }
  133.     seconde = 0;
  134.     touch = 0;
  135.     Serial.println("led OFF");
  136.   }
  137. }
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement