November 21, 2024, 05:15:25 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Prop-1 / LCD/ Solenoid

Started by gadget-evilusions, October 30, 2013, 10:27:10 AM

Previous topic - Next topic

gadget-evilusions

Hello,

I am asking for help, as I don't fully understand outputting to an LCD display yet.

I have a Parallax 2 x 16 back lit serial LCD, 27977. A Prop-1, an normally open switch, and a 10k potentiometer.

1. I would like a program to read the potentiometer, and convert that input to a range of 0-500ms.
2. Display that 0-500ms value on the LCD screen in semi-real time.
3. When the normally open switch is pressed, I want to turn on a 12vdc solenoid, hooked up to Out1, for a time equal to the 0-500ms range from the potentiometer.
4. Reset.

It's the monitoring of the pot and displaying it on the LCD that is befuddling me.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Sorry for the delay. Here's a simple version to get things started. Once things are working we can tweak the value. Remember that the Prop-1 has an in-line resistor on the IO pins so the pot will never go down to zero; once you know what the low-end value is we can adjust that out.

Notice that the debounce loop is actually using the time to read the pot and update the display as its timing pad.

' =========================================================================
'
'   File...... solenoid_timer.bs1
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Adjust          = 7                     ' no ULN, SETUP = REMOVED
SYMBOL  TX              = 6                     ' no ULN, SETUP = DN
SYMBOL  Trigger         = PIN5                  ' N.O. between P5.R & P5.W

SYMBOL  Solenoid        = PIN1                  ' V+ and OUT1


' -----[ Constants ]-------------------------------------------------------

SYMBOL  YES             = 1
SYMBOL  NO              = 0

SYMBOL  IS_ON           = 1
SYMBOL  IS_OFF          = 0


' LCD

SYMBOL  LCD_BKSPC       = $08                   ' move cursor left
SYMBOL  LCD_RT          = $09                   ' move cursor right
SYMBOL  LCD_LF          = $0A                   ' move cursor down 1 line
SYMBOL  LCD_CLS         = $0C                   ' clear LCD (use PAUSE 5 after)
SYMBOL  LCD_CR          = $0D                   ' move pos 0 of next line
SYMBOL  LCD_BLON        = $11                   ' turn backlight on
SYMBOL  LCD_BLOFF       = $12                   ' turn backlight off
SYMBOL  LCD_OFF         = $15                   ' LCD off
SYMBOL  LCD_ON1         = $16                   ' LCD on; cursor off, blink off
SYMBOL  LCD_ON2         = $17                   ' LCD on; cursor off, blink on
SYMBOL  LCD_ON3         = $18                   ' LCD on; cursor on, blink off
SYMBOL  LCD_ON4         = $19                   ' LCD on; cursor on, blink on
SYMBOL  LCD_LINE1       = $80                   ' move to line 1, column 0
SYMBOL  LCD_LINE2       = $94                   ' move to line 2, column 0

SYMBOL  LCD_CC0         = $F8                   ' define custom char 0
SYMBOL  LCD_CC1         = $F9                   ' define custom char 1
SYMBOL  LCD_CC2         = $FA                   ' define custom char 2
SYMBOL  LCD_CC3         = $FB                   ' define custom char 3
SYMBOL  LCD_CC4         = $FC                   ' define custom char 4
SYMBOL  LCD_CC5         = $FD                   ' define custom char 5
SYMBOL  LCD_CC6         = $FE                   ' define custom char 6
SYMBOL  LCD_CC7         = $FF                   ' define custom char 7


' -----[ Variables ]-------------------------------------------------------

SYMBOL  debounce        = B2                    ' for trigger debouncing
SYMBOL  digit           = B3

SYMBOL  solTiming       = W5


' -----[ Initialization ]--------------------------------------------------

Power_Up:
  HIGH TX                                       ' set LCD serial to idle
  PAUSE 250                                     ' let LCD initialize
  SEROUT TX, T2400, (LCD_BLON, LCD_ON1, LCD_CLS)

Reset:
  PINS = %01000000                              ' set LCD serial to idle
  DIRS = %01000010                              ' set P6 and P1 to output

  debounce = 0


' -----[ Program Code ]----------------------------------------------------

Main:
  POT Adjust, 100, solTiming                    ' *** Use Run->Pot Scaling

  solTiming = solTiming * 2 MAX 500             ' scale and limit

  ' update LCD

  SEROUT TX, T2400, (LCD_LINE1)                 ' cursor home

  digit = solTiming / 100 + "0"                 ' extract 100s
  SEROUT TX, T2400, (digit)

  solTiming = solTiming // 100
  digit = soltiming / 10 + "0"                  ' extract 10s
  SEROUT TX, T2400, (digit)

  solTiming = solTiming // 10 + "0"             ' extract 1s
  SEROUT TX, T2400, (digit)


Check_Trigger:
  debounce = debounce + 1 * Trigger             ' count display loops
  IF debounce < 10 THEN Main


Run_Solenoid:
  Solenoid = IS_ON
  PAUSE solTiming
  Solenoid = IS_OFF
  GOTO Reset


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office