Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1.  
  2. #include <FastLED.h>
  3.  
  4. /* Knock Sensor
  5.  *  
  6.  *  Code has been modified for the Tapping Light, by PerfectPixel (2015)
  7.  *  http://www.instructables.com/member/perfectpixel/
  8.  *  
  9.  *  
  10.    created 25 Mar 2007
  11.    by David Cuartielles <http://www.0j0.org>
  12.    modified 30 Aug 2011
  13.    by Tom Igoe
  14.  
  15.    This example code is in the public domain.
  16.  
  17.  */
  18.  
  19. #define NUM_LEDS 1
  20.  
  21. #define DATA_PIN 9
  22.  
  23. CRGB leds[NUM_LEDS];
  24.  
  25. int sensorReading = 0;      // variable to store the value read from the sensor pin
  26.  
  27. void setup() {
  28.  FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  29. }
  30.  
  31. void loop() {
  32.   if (analogRead(7) > 2) { //change the "2" here to a different value to tweak what counts as a 'tap'
  33.     // toggle the status of the ledPin:
  34.     leds[0] = CRGB(random(300),random(300),random(300));
  35.       FastLED.show();
  36.     delay(10);
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement