Shop OBEX P1 Docs P2 Docs Learn Events
Using an LED as a button — Parallax Forums

Using an LED as a button

piguy101piguy101 Posts: 248
edited 2014-01-24 16:36 in General Discussion
Using the Mims effect of LEDs, I programmed the Propeller to use an LED as a button. The LED turns on when it is touched and off when it is touched again. Ignore all the other circuitry as it is from a game of simon that I didn't want to tear apart. Currently, the "button" is flaky and only responds ~80% of the time. Because there are no moving parts like a conventional button, this will never wear out, but when I turn the light in the room on and off, the button is activated. :smile:
Sorry, the code isn't commented and is probably impossible to understand my logic, but there is a schematic.
{{LED Button
Uses the Mims effect to use an LED as a button without any
moving parts like a button. By sensing sudden changes in light, the
Propeller detects a finger on the LED and illuminates the LED
until the LED is touched again. The LED functions as a photodiode
and a counter module measures the time for the R/C circuit to
fall. No  capacitor is needed in this case as the solderless breadboard
provides enough stray capacitance.


                 47Ω
P11───┳────┳────P10
       │      │
       └────┘
         10MΩ
         
}}         
con       
_clkmode=xtal1+pll16x
_xinfreq=5000000
pub main | time1, time2, index, power
ctra[30..26]:=000
ctra[5..0]:=10
frqa:=1
dira[11]~~
dira[16]~~
repeat 10
  dira[10]:=outa[10]:=1
  waitcnt(clkfreq/100000+cnt)
  phsa~
  dira[10]~
  waitcnt(clkfreq/1000+cnt)
  time2+=phsa
time2/=10
repeat
  repeat 10
    dira[10]:=outa[10]:=1
    waitcnt(clkfreq/100000+cnt)
    phsa~
    dira[10]~
    waitcnt(clkfreq/1000+cnt)
    time1+=phsa
  time1/=10
  if ||(time1-time2)>30
    index+=1   
    if index//2==1
      if power==0
        power:=1
      elseif power==1
        power:=0
      waitcnt(clkfreq/10+cnt)
  time2:=0
  if power==0
    dira[10]:=dira[11]:=outa[10]:=outa[11]:=0
  elseif power==1
    dira[10]:=dira[11]:=outa[11]:=1
    outa[10]:=0
  waitcnt(clkfreq/1000+cnt)
  dira[10]:=outa[10]:=outa[11]:=0
  dira[11]:=1
  repeat 10
    dira[10]:=outa[10]:=1
    waitcnt(clkfreq/100000+cnt)
    phsa~
    dira[10]~
    waitcnt(clkfreq/1000+cnt)
    time2+=phsa
  time2/=10
  if ||(time1-time2)>30
    index+=1   
    if index//2==1
      if power==0
        power:=1
      elseif power==1
        power:=0
      waitcnt(clkfreq/10+cnt)
  time1:=0
  if power==0
    dira[10]:=dira[11]:=outa[10]:=outa[11]:=0
  elseif power==1
    dira[10]:=dira[11]:=outa[11]:=1
    outa[10]:=0
  waitcnt(clkfreq/1000+cnt)
  dira[10]:=outa[10]:=outa[11]:=0
  dira[11]:=1

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-01-24 16:17
    Clock Loop has a really cool project using LEDs as buttons. I think he got his buttons to work pretty consistently.

    I haven't ever tried this myself. I really like the idea of the button never wearing out. It seems like it's also a great way of having a water proof button.
  • Clock LoopClock Loop Posts: 2,069
    edited 2014-01-24 16:36
    I have found that the mini leds work great for this.

    The detection ability and reliability of the "LED BUTTON" completely depends on the wavelength of led you choose, ALONG with the overhead lighting you have in the room.
    The only way to defeat environment lighting is to provide your own.

    In this image, the ccfl tube is mounted directly above the leds for absolute operation in all environments.
    front.jpg


    The concept that mimms discovered is nothing more than a tripline using an led as detector. A led as emitter, and the same led as detector. This ensures same wavelength.
    Concept could be used with other wavelength, i.e. uv, ir, etc... Some leds are better detectors than others.

    Mini RED leds seem to work best, along with an incandescent.
    The led on the very left side is the mini.
    Verschiedene_LEDs.jpg
    1024 x 360 - 30K
    1024 x 360 - 21K
Sign In or Register to comment.