Photocell+Video(MAX) using Serout command - Zen
Here is the working code.
I made sure my PBasic code was working before attempting to connect the Basic Stamp with MAX. The command for connecting these two languages (PBasic and MAX) is SEROUT.
It is put in to my code as a subroutine, at the end of the cycle. THe first place you will see this is under MAIN, as a subroutine Send_Data. Then you will find the actual routine near the end of the code.
I am using Pin 7 (Serout 7). THe speed the data is sent is 16624. The next two numbers are critical, and I remember their meaning as "1" is the gate that has to be opened to send the data, and "value" is the data being sent. I have defined "value" in my declarations, so PBasic is sending my readings (from the photocell) in huge quantities, as defined by Word. (This is all on page 53 of the Basic Stamp manual)
I am grunting every step of this journey - as if you couldn't tell.
enjoy....
' {$STAMP BS2sx}
'REFERENCE POINTS:
'PHOTOCELL1 VAR Word
'Reference:
'page 50 Basic Stamp Manual for definition of defining Variables
'VAR WORD 'Value can be 0 to 65535
'This sets the range of numbers that will impact the relationships
'BREADBOARD NEEDS:
'Power in
'Regulator
'ADC Stamp and the usual wiring (big brain)
'ADC chip (small brain)
'LIGHT DETECTOR NEEDS:
'Photoresistor or Photocell - 'Photo sensor being used is Cadmium Sulfide (CdS)
'Resistor 220 red-red-brown
'Capacitor (these are ceramic things that look like a guber on 2 wires
'Jumper wires (those little wire things that connect from the brain to the power or ground)
'GOAL OF THIS PROGRAM - to read the photoresistor in RCTime
'RCTime is the pin statement variable - Resistance of Capacitance
' WHAT DO I WANT IT ALL TO DO
' Have the LED on all the time,
' Have the LED turn off when the shadow is strong enough on the Photocell
' Have the LED react to the reading from the photocell
' When the Photocell gives a reading in a certain range, it shuts down the LED
' Then the LED is made to come back on
'ORGANIZING FOR BUILDING THE CODE
'Make my declarations
'Define the list of contents for Main (all of the subroutines)
'ledOn to turn the LED on
'Shutdown to turn the LED off (when interupted by the photocell)
'DECLARATIONS
value VAR Word
'I don't need to declare what the LED is
Main:
GOSUB PHOTOCELL1
GOSUB DECIDE
GOSUB DISPLAY
GOSUB SEND_DATA
GOTO main
'SUBROUTINE FOR PHOTOCELL
'This is to activate the Photocell
PHOTOCELL1:
HIGH 8 'Out of pin 8
PAUSE 1 'the cell should be on all the time, receiving light
RCTIME 8, 1, value ' measure RC discharge time
RETURN
'in daylight 1900 is the cutoff point. number range is 1100 - 2400 in day.
'SUBROUTINE FOR LED
'This will turn the LED on, and tell it when it will be turned off.
DECIDE: 'this subroutine is all about the decisions that are being made
'when the photocell value has a reading above >=1900, it shuts off the led
'when the value of the photocell reading is <=1899 then the led comes back on
IF value >= 1100 THEN SHUTDOWN
IF value <= 1099 THEN LEDON
'the number reads bigger, the darker the environment,late at night, 2900+
RETURN
' ------ [ sub routines for DECIDE ] --------------
'instead of putting SHUTDOWN and LEDON as separate subroutines, they are in DECIDE
'this tells me that the DECIDE subroutine is driving the program
SHUTDOWN:
LOW 7
PAUSE 0
RETURN
LEDON:
HIGH 7 'out of pin 7
PAUSE 0 'this will keep it on all of the time
RETURN
DISPLAY: 'this subroutine runs the debug program and displays the values
'DEBUG DEC ? value ' display value
RETURN 'take debug out when stamp is programmed
'MAX doesn't like debug
SEND_DATA
SEROUT 7, 16624, [1,value] 'this identifies the pin on the basic stamp
PAUSE 2 'this just lets it all breath a beat
'SEROUT 7, 16624'the number 16624 is a logirithmic number for defining buckets of data
'if I was using an adcbit - small brain; chip, then i would code this in
'it would look like (adcbits 1)
RETURN
'the way you stop this running is to unplug tip positive
'============================================























































