Scale 8bit ADC RGB LED voltmeter


Results 1 to 2 of 2

Threaded View

  1. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    disable
    blue var byte:green var byte:red var byte:greenled var gpio.0
    redled var gpio.1:ansel=$68:greenled var gpio.0:trisio=0:temp var word
    pwmcount var byte:adread var word:adcon=$8d:goto mainloop
    on interrupt goto inthandle
    inthandle:
    if intcon.2 = 1 then   'tmr 0 overflow fired off
         intcon.2 = 0 : pwmcount = pwmcount + 1 : if pwmcount = 0 then gpio = 0
         if green > pwmcount then greenled = 1
         if blue > pwmcount then blue = 1
         if red > pwmcount then red = 1
    endif
    if pir1.6 = 1 then      'a/d convert int fired off
    pir1.6=0:adread.highbyte=adresh:adread.lowbyte=adres
    if adread < 327 then adread = 0  'if less than minimum zero it
    if adread > 460 then adread = 133  'if more than max, max it out
    adread = adread - 327  'range of 133 (.0048828125 volts/bit)
    adread = adread * 30   'scale it up to reach 12 usable bits
    red=0:red.7=adread.11:red.6=adread.10:red.5=adread.9:red.4=adread.8
    blue=0:blue.7=adread.7:blue.6=adread.6:blue.5=adread.5:blue.4=adread.4
    green=0:green.7=adread.3:green.6=adread.2:green.5=adread.1:green.4=adread.0
    endif
    resume
    enable
    mainloop:     @ nop
    if adcon.1 = 0 then adcon.1 = 1
    @ nop
    goto waitforad
    End
    Try that for grins...
    The LEDs should follow the voltage from 0 to 5v. If it actually works (I haven't tried it), you should be able to scale adread when it's read according to what you want to do. I just threw this together. Anything less than 1.6v, LEDs are dark, more than 2.25v LEDs are full bright, anything in between, the number gets converted to a 12bit value, high 4 bits to red, mid 4 bits to green, low 4 bits to blue.
    Last edited by skimask; - 22nd February 2008 at 04:49. Reason: Changed it up a bit

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 07:14
  2. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 05:59
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 21:19
  4. RGB LED Matrix
    By ERIK in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th June 2008, 08:01
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 03:30

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts