I can't really say for sure what is going on without seeing more info, but from my understanding of the code, it seems that you're calling checkFinger() in a pretty quick loop, and that if it gets what it thinks to be a positive reading it toggles the LED. So if your sensor was working, when you touched the lamp, the LED would flicker quickly. So I think if your sensing isn't working right and thinks you're touching the lamp, a quickly flickering LED is just what I'd expect. I think what you need is something like: int last_switch = 0; // global // then in your check finger loop if(GPIO3) { if(!last_switch) { toggleLed(); last_switch = 1; } } else { last_switch = 0; } I also wouldn't be surprised if there are hardware or firmware issues with the sensing technique. Have you seen http://www.qprox.com/products/product_summary.html ? -n. On Wed, Jun 18, 2008 at 9:03 PM, mossy173 wrote: > > Enormous thanks to everyone for the help on the last project. That's now > done and working well, and I'm on to something bigger and just as > inexplicably nonfunctional. I have the PIC wired with a metal lamp between > pins 3 and 4, and an LED between pin 0 and ground. The idea here is to > charge and discharge the body of the lamp very quickly, and if at any point > discharging takes too long, that indicates human contact and accompanying > increase in capacitance. Instead, the LED just flickers very quickly and > dimly regardless of input. The wait time here is very high just to make > sure that the lamp lights, which it fails to. Any ideas?? > > -Eli > > > #include > #define LED GPIO0 > #define OFF 0 > #define ON 1 > #define EMITTOR GPIO2 > > void checkFinger(void); > void init(void); > void delay(int delay); > void toggleLED(void); > > void main(void){ > init(); > LED = ON; > while(1){ > > checkFinger(); > > > } > } > int z; > void checkFinger(void){ > > EMITTOR = 1; > > for (z = 0; z < 300; z++) > NOP(); > > if (GPIO3 == 1) > toggleLED(); > > EMITTOR = 0; > delay(200); > } > > void toggleLED(void){ > if (LED == ON) > LED = OFF; > else > LED = ON; > } > > void init(void){ > ANS3 = 0; > VRCON = 0; //Turn Off Voltage Reference Peripheral > CMCON = 0x07; //Turn Off Comparator Peripheral > TMR0 = 0; //Clear Timer0 > > OPTION = 0x80; > > > TRIS3 = 1; > TRIS2 = 0; > TRIS0 = 0; > > // INTCON = 0; > /* IOCB4 = 1; //interrupt on change for pin 4 is on > IOCB = 0x00010000; > GPIE = 1; > T0IF = 0; > T0IE = 1; */ > > } > > void delay(int delay){ > int x, y; > for (x = 0; x< delay; x++){ > for (y = 0; y<100; y++){ > NOP(); > } > } > } > -- > View this message in context: http://www.nabble.com/newb%27s-capacitance-switch-implementation-tp17995271p17995271.html > Sent from the PIC - [PIC] mailing list archive at Nabble.com. > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist