PDA

View Full Version : Basic Stamp 2 programing help



cocush
02-02-2010, 12:59 PM
Hello,

I am new to this forum and needed help figuring out how to write a program in BS2.·I need to construct a light-meter using·4 LED's to display five states; light level from 0 to 20% (no·LED's on), 20to 40% (1 LED on) , 40 to 60% ( 2 LED's on) and 60 to 80%·(3 LEDs on) and· 80 to 100% ( 4 LEDs on). and the percentage pertains to light level, so a very dark room would have 0% and·very bright would be 100%. I was reading the·BS2 manual and figured i need to use a photocell and a capacitor along with the RCtime command but i have no idea how to start or write the program. If anybody knows how to write or can help me figuring out·how to.

Thank you.···························

Mike Green
02-02-2010, 01:11 PM
Assuming you have the BS2 and the photocell and capacitor, you should start with the sample programs for the RCTIME statement and try them out. You'll find that using the RCTIME statement is very non-linear and you'll have to calibrate the process to figure out what values you'll get for any given light level. You'll be using the DEBUG statement so you can see what the values are. Given the coarseness of the light levels, you will probably be able to use a single capacitor value to get numeric thresholds for each of the light levels you want to use. The photocell has the highest resistance in the dark, so you'll have some relatively high number for 20%, a lower number for 40%, still lower for 60%, and very low for 80%. For your program, you'd use IF statements to check which group of values your actual reading falls into and light the proper number of LEDs.

The references you need are "What's a Microcontroller?" and the "BASIC Stamp Syntax and Reference Manual". Work through the problems in "What's a Microcontroller?".

cocush
02-03-2010, 03:38 AM
Thank You For replying.