PDA

View Full Version : Cry for help,



BigW
01-20-2007, 01:53 AM
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,

bigw2069 @ hotmail(dot)com (mailto:bigw2069@ hotmail(dot)com)



·

allanlane5
01-20-2007, 02:18 AM
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)?

BigW
01-20-2007, 02:27 AM
Apologies, Yes its the board of education BS2, Pbasic 2.5

allanlane5
01-20-2007, 02:43 AM
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.

BigW
01-20-2007, 02:48 AM
Thanks Allan, I have those texts on screen in front of me at the moment and i'll continue trawling them,

Cheers

BW

BigW
01-20-2007, 08:06 AM
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?

' -----[ Title ]-----------------------------------------------------------

' Temperaure Measurement using ADC0831, LM358 & LM35
' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[ Declarations ]----------------------------------------------------
adcBits VAR Byte
t VAR Byte
r VAR Byte
t2 VAR Byte
t3 VAR Byte
' -----[ Initialization ]--------------------------------------------------
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS 'Start display.
' -----[ Main Routine ]----------------------------------------------------
DO
GOSUB ADC_Data
GOSUB Calc_Temp
GOSUB Display
LOOP
' -----[ Subroutines ]-----------------------------------------------------
ADC_Data:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[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 arse in the right direction please?

Re

BW

PJ Allen
01-20-2007, 08:33 AM
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