Shop OBEX P1 Docs P2 Docs Learn Events
Cry for help, — Parallax Forums

Cry for help,

BigWBigW Posts: 4
edited 2007-01-20 01:33 in BASIC Stamp
Hi all, I joined the Yahoo usergroup some time ago·but it seems to be pretty dead, then I stumbled across you guys while looking for some inspiration.

This is a long shot but I am having some troubles writing a couple of "Very simple" codes for my uni class, I work with nuts and bolts all day long but this is part of the curriculum so it must be done,

Would somebody be willing to give me a little hand with these programs over email and I would happily sort them out with a few beer tokens if so required, One is simply temperature measurement and alarm and the other is a pushbutton with lights, and a servo motor to open a door.

It would be appreciated

Re

BW,

[url=mailto:bigw2069@ hotmail(dot)com]bigw2069 @ hotmail(dot)com[/url]



·

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-19 19:18
    Well, you don't mention it, but I assume you're trying to implement these with some BS2 variant? And perhaps a Board Of Education (BOE)?
  • BigWBigW Posts: 4
    edited 2007-01-19 19:27
    Apologies, Yes its the board of education BS2, Pbasic 2.5
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-19 19:43
    You probably should go to the Parallax website and download the "What's a Microcontroller" text. That, and the "Analog and Digital Interfacing".

    Skim those to find the parts you need. Another resource is the "nuts&Volts" articles, also on the Parallax website. These are very concise examples, with code, of implementing just what you're trying to do.
  • BigWBigW Posts: 4
    edited 2007-01-19 19:48
    Thanks Allan, I have those texts on screen in front of me at the moment and i'll continue trawling them,

    Cheers

    BW
  • BigWBigW Posts: 4
    edited 2007-01-20 01:06
    Ok so a couple of beers to the better and 10 hours work have allowed me to produce enough code to measure the temperature in the room,

    How does this look to you knowlegable chaps out there?

    '
    [noparse][[/noparse] Title ]

    ' Temperaure Measurement using ADC0831, LM358 & LM35
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    [noparse][[/noparse] Declarations ]
    adcBits VAR Byte
    t VAR Byte
    r VAR Byte
    t2 VAR Byte
    t3 VAR Byte
    '
    [noparse][[/noparse] Initialization ]
    CS PIN 0
    CLK PIN 1
    DataOutput PIN 2
    DEBUG CLS 'Start display.
    '
    [noparse][[/noparse] Main Routine ]
    DO
    GOSUB ADC_Data
    GOSUB Calc_Temp
    GOSUB Display
    LOOP
    '
    [noparse][[/noparse] Subroutines ]
    ADC_Data:
    HIGH CS
    LOW CS
    LOW CLK
    PULSOUT CLK, 210
    SHIFTIN DataOutput,CLK,MSBPOST,[noparse][[/noparse]adcBits\8]
    RETURN
    Display:
    DEBUG HOME
    DEBUG "8-bit binary value: ", BIN8 adcBits
    DEBUG CR, CR, "Decimal value: ", DEC3 adcBits
    DEBUG CR, CR, "Temperature Reading: "
    DEBUG DEC2 t, ".", DEC2 t2, " Degrees C"
    RETURN
    Calc_Temp:
    t = 50 * adcBits / 255
    r = 50 * adcBits // 255
    t2 = 100 * r / 255
    t3 = 100 * r // 255
    t3 = 10 * t3 / 255
    IF (t3 >= 5) THEN t2 = t2 + 1
    IF (t2 >= 100) THEN
    t = t + 1
    t2 = 0
    ENDIF
    RETURN
    _____________________________________________________________________________________

    I dont have the hardware here at the moment but the syntax checks out ok.

    I have confused myself at this point though, I am looking to add an audible alarm and red LED if the temp drops below 10 Degrees or above 20 degrees and a green LED if it is between 10 and 20.

    any chance of a kick up the Smile in the right direction please?

    Re

    BW
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-01-20 01:33
    OK,·here's a 10 1/2 wide sub-routine:

    IF (tempC < 10) THEN HIGH 1     'Red LED on P1
    ELSEIF (tempC >20) THEN HIGH 1  'Red LED on P1
    ELSE HIGH 2                     'Green LED on P2  within window
    ENDIF
     
    
Sign In or Register to comment.