Advertisement
UnaClocker

ATTiny Capsense LightSwitch

Nov 24th, 2013
1,481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <CapacitiveSensor.h>
  2.  
  3. /*
  4.  * Based on the CapitiveSense Library Demo Sketch
  5.  * which was written by Paul Badger 2008
  6.  * Uses a high value resistor (in this case, 750k ohm) between send pin and receive pin
  7.  * Resistor effects sensitivity, Larger resistor values yield larger sensor values.
  8.  * Receive pin is the sensor pin
  9.  - Final sketch written by Brian Schulteis - The UnaClocker, November 2013
  10.  - Uses an ATTiny85 running at 8MHz on the internal oscillator, to control an XBox 360 power supply
  11.  - 5v is provided by the 5v standby power of the XBox 360 power supply.
  12.  */
  13.  
  14. boolean lightOn=false; // I like booleans
  15. CapacitiveSensor   tapper = CapacitiveSensor(0,1); // 750k resistor between pins 0 & 1, pin 1 is sensor pin
  16. unsigned long lastTap; // Used as a kind of a debounce effect
  17.  
  18. void setup()                    
  19. {
  20. pinMode(3, OUTPUT);
  21. digitalWrite(3, lightOn);
  22. lastTap=millis();
  23. }
  24.  
  25. void loop()                    
  26. {
  27.  
  28.     if (tapper.capacitiveSensor(30) > 50) {
  29.       if ((millis()-lastTap)>500) {
  30.       lightOn=!lightOn;
  31.       lastTap=millis();
  32.       }
  33.     }
  34.     delay(50);
  35.     digitalWrite(3, lightOn);
  36.  
  37.     delay(100);                             // arbitrary delay to limit oversampling the pin
  38.                                             // May cause quick taps to be missed, that's ok by me.
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement