Shop OBEX P1 Docs P2 Docs Learn Events
Remote control using IR Quickstart/Human Interface Combo — Parallax Forums

Remote control using IR Quickstart/Human Interface Combo

skylightskylight Posts: 1,915
edited 2013-01-11 19:36 in Propeller 1
After making a complete fool of myself posting in an earlier thread about not understanding some of the demos for the Quickstart and Human Interface I spent the evening playing around with several objects from the OBEX and although a beginner with spin I've started to get a real feel for it and adapted an IR spin program from the exchange that now recognises the numbered keys 1-8 on a remote and turns on the appropriate LED with key 0 turning them all off, I feel i've acomplished something tonight and this will definitely encourage me to go forward with the propeller.

Below is the adapted code and attachment, thanks to Bob Belleville for the original code.
{{ ir_reader_demo.spin
  Bob Belleville
  This object receives input from an IR remote using
  object ir_reader_nec.spin or ir_reader_sony.spin.
  This is a good tool to use to build a table showing
  the key code for each button.
  see readme.pdf for more documentaton
  2007/03/01 - derived from ir_reader_nec_show.spen
               and tv_terminal_demo.spin
  2007/03/03 - generalized for nec and sony objects
               provide method to get device ID
  2013/01/12  Adapted code to work with Quickstart/Human Interface Board combo
                Lines added are commented "HIB Addition"        
               
}}
 
CON
                                'will NOT work at other speeds
        _clkmode        = xtal1 + pll16x
        _xinfreq        = 5_000_000
        _irrpin         = 8     'ir receiver module on this pin   HIB Addition changed from 0 to Pin 8 for Human Interface Board
        _device         = 0     'accept any device code
        _dlyrpt         = 6     'delay before acception code as repeat
        
VAR
OBJ
                                'select one rcvir and one term
                                
        rcvir   : "ir_reader_nec"
        'rcvir   : "ir_reader_sony"
        'rcvir   : "ir_reader_rc5"
        'term    : "tv_terminal"
        term    : "serial_terminal"

PUB start | keycode, x
  
  term.start(12)                'start the tv terminal
  term.str(@title)
  rcvir.init(_irrpin,_device,_dlyrpt,true)   'startup
  
   dira[23..16]:=255            'HIB Addition
  repeat
    keycode := rcvir.fifo_get   'try a get from fifo
    if keycode == -1            'empty try again
      next
    if keycode & $80
      term.out("R")             'show repeated code
      term.dec(keycode & $7F)
    else
      term.dec(keycode)         'show code
    if keycode == 17            'HIB Addition
    
     outa[16]:=1                 'HIB Addition
    if keycode == 18             'HIB Addition
     outa[17]:=1                 'HIB Addition
    if keycode == 19             'HIB Addition
     outa[18]:=1                 'HIB Addition
    if keycode == 20             'HIB Addition
     outa[19]:=1                 'HIB Addition
    if keycode == 21             'HIB Addition
     outa[20]:=1                 'HIB Addition
    if keycode == 22             'HIB Addition
     outa[21]:=1                 'HIB Addition
    if keycode == 23             'HIB Addition
     outa[22]:=1                 'HIB Addition
    if keycode == 24             'HIB Addition
     outa[23]:=1                 'HIB Addition
    if keycode == 16             'HIB Addition
     outa[23..16]:=0             'HIB Addition
       
    sp
                                'device code is in low 16 bits
    term.hex(rcvir.fifo_get_lastvalid,8)
    nl
    {
    x := rcvir.fifo_debug       'show fifo head and tail pointers
    term.dec(x>>16 & $FFFF)     'fifo head
    term.out(":")
    term.dec(x & $FFFF)         'fifo tail
    nl
    }
    
    
PUB sp
  term.out(" ")
PUB nl
  term.out(13)
  term.out(10)
    
DAT
title   byte    "Push ir button for codes",13,13,0
ir_reader_demoHIB.spin
ir_reader_nec.spin
Sign In or Register to comment.