FIREMANJIM
New Member
My question is after you name the pins on the picaxe chip does it matter what order you list the variables? can you list the word variables before the bit and byte variables? I generally list all my bits then my bytes and then my word variables. A friend sent me the code below and I seen where his variables are all mixed up....Does this matter? Thanks for your help.
Code:
#rem
Picaxe 14m2
Dip 3 is for Trail or Feeder modes. Switch 1 ON is Feeder mode - OFF is Trail mode
Dips 1 and 2 are used to select the delay in feered mode
Dip 1 off and Dip 2 off selects 30 second delay
Dip 1 off and Dip 2 on selects 1 minute delay
Dip 1 on and Dip 2 off selects 3 minute delay
Dip 1 on and Dip 2 on selects 6 minute delay
#endrem
symbol CdsIn = b.3
symbol CdsPwr = b.2
symbol LED = b.4
symbol Shutter = c.1
symbol CamPwr = c.0
symbol Opto2Port1 = b.5 ' opto 2 terminal 1
symbol Opto2Port2 = b.0 ' opto 2 terminal 2
symbol PirIn = pinc.2
symbol DIP1 = pinc.4 ' Dip Switch 1 input
symbol DIP2 = pinc.3 ' Dip Switch 2 input
symbol DIP3 = pinb.1 ' Dip Switch 3 input
symbol DayStatus = bit0
symbol Type4 = bit1
symbol CDSTimer = w12
symbol LightLevel = b4
symbol DaySetting = b5
symbol NightSetting = b6
symbol Counter = b7
symbol FeederDelay = b8
symbol FeederMode = bit5
symbol CameraOn = bit2
symbol CameraRefreshTimer = w9
symbol CameraRefreshTime = w10
symbol ShutterDelay = w11
disablebod
' outputs as low
low LED
low CamPwr
low Shutter
Low CdsPwr
low Opto2Port1
low Opto2Port2
' set input pins as inputs
Input b.1
Input b.3
Input c.2
Input c.3
Input c.4
' set default variable settings
CameraOn = 0
DayStatus = 1
DaySetting = 60
NightSetting = 50
Type4 = 0
ShutterDelay = 2000
w13 = 0
nap 5 ' To let power settle if needed before checking dip switch settings
' check if Feeder Mode dip switch is on
if DIP3 = 0 then
FeederMode = 1 ' run in feeder mode
else
FeederMode = 0 ' run in trail mode
endif
' Setup camera timing for the rest of the operation of the camera
' Dip switches are Low when ON. When OFF they are High
' DIP 1 and DIP 2 is OFF so 30 second feeder delay
if DIP1 = 1 and DIP2 = 1 Then
FeederDelay = 14
' DIP1 1 Off and DIP 2 is ON so 1 minute delay
elseif DIP1 = 1 and DIP2 = 0 Then
FeederDelay = 28
' DIP 1 ON and DIP 2 OFF so feeder delay is 3 minutes
elseif DIP1 = 0 and DIP2 = 1 Then
FeederDelay = 79
' DIP 1 is ON and DIP 2 is ON so a 6 Minute feeder delay
elseif DIP1 = 0 and DIP2 = 0 Then
FeederDelay = 157
endif
'turn on camera to test and charge flash cap
High LED
Pause 1000
high CamPwr
pause 500
low CamPwr
sleep 5
high CamPwr
pause 500
low CamPwr
Pause 1000
Low LED
sleep 1
CameraRefreshTimer = 0
pause 1000
WalkTest:
nap 2 ' nap for 72ms .072 seconds
if PirIn = 1 then
high LED
nap 6 ' pause low power for 1.1 seconds
low LED
nap 8 ' pause low power for 4 seconds
w13 = 0
endif
if w13 >= 416 then ' approx 30 seconds
let b9 = 10
for Counter = 1 to b9
high LED
pause 200
low LED
pause 200
next Counter
pause 1000
goto CDSCheck
endif
w13 = w13 + 1 ' increment loop counter
goto WalkTest
CDSCheck:
high CdsPwr ' apply power to CDS sensor
nap 5 ' allow power to settle
readadc CdsIn, LightLevel
low CdsPwr
if LightLevel >= DaySetting then
DayStatus = 1
CameraRefreshTimer = 0
CDSTimer = 0
elseif LightLevel < NightSetting then
DayStatus = 0
CameraRefreshTimer = 0
CDSTimer = 0
endif
main:
'daytime run code
if Daystatus = 1 then
if PirIn = 1 then
if FeederMode = 1 then
if CameraOn = 0 then ' if camera is off turn it on
high CamPwr
pause 500
low CamPwr
CameraOn = 1
pause ShutterDelay
endif
high Shutter ' Press Shutter Button to take picture
pause 3000
low Shutter
sleep 5
high CamPwr ' turn camera off in feeder mode
pause 500
low CamPwr
CameraOn = 0
w5 = 0
sleep FeederDelay
endif
if FeederMode = 0 then
if CameraOn = 0 then ' if camera is off turn it on
high CamPwr
pause 500
low CamPwr
CameraOn = 1
pause ShutterDelay
endif
high Shutter ' Press Shutter Button to take picture
pause 3000
low Shutter
pause 1000
w5 = 0
endif
CameraRefreshTimer = 0 ' reset camera refresh counter/timer
endif
if CameraOn = 1 then
w5 = w5 + 1 ' increment temporary counter for camera on time with no pir activity
if w5 >= 200 then ' camera timer set to about 20 seconds no activity
high CamPwr ' turn camera off
pause 500
low CamPwr
CameraOn = 0
w5 = 0
sleep 2
endif
endif
CameraRefreshTimer = CameraRefreshTimer + 1
if CameraRefreshTimer >= CameraRefreshTime then
high CamPwr
pause 500
low CamPwr
sleep 5
high CamPwr
pause 500
low CamPwr
sleep 1
CameraRefreshTimer = 0
pause 1000
endif
CDSTimer = CDSTimer + 1
If CDSTimer >= 2084 then ' check time every 2 1/2 minutes
high CdsPwr ' apply power to CDS sensor
nap 5 ' allow power to settle
readadc CdsIn, LightLevel
low CdsPwr
if LightLevel < NightSetting then
DayStatus = 0
else DayStatus = 1
CameraRefreshTimer = 0
CDSTimer = 0
if CameraOn = 1 then
high CamPwr
pause 500
low CamPwr
CameraOn = 0
endif
nap 2
goto main
endif
CDSTimer = 0
endif
endif
'nighttime run code
if Daystatus = 0 then
if PirIn = 1 then
if FeederMode = 1 then
if CameraOn = 0 then ' if camera is off turn it on
high CamPwr
pause 500
low CamPwr
CameraOn = 1
pause ShutterDelay
endif
high Shutter ' Press Shutter Button to take picture
pause 3000
low Shutter
sleep 5
high CamPwr ' turn camera off in feeder mode
pause 500
low CamPwr
CameraOn = 0
w5 = 0
sleep FeederDelay
endif
if FeederMode = 0 then
if CameraOn = 0 then ' if camera is off turn it on
high CamPwr
pause 500
low CamPwr
CameraOn = 1
pause ShutterDelay
endif
high Shutter ' Press Shutter Button to take picture
pause 3000
low Shutter
sleep 5
w5 = 0
endif
CameraRefreshTimer = 0 ' reset camera refresh counter/timer
endif
if CameraOn = 1 then
w5 = w5 + 1 ' increment temporary counter for camera on time with no pir activity
if w5 >= 200 then ' camera timer set to about 20 seconds no activity
high CamPwr ' turn camera off
pause 500
low CamPwr
CameraOn = 0
w5 = 0
sleep 2
endif
endif
CameraRefreshTimer = CameraRefreshTimer + 1
if CameraRefreshTimer >= CameraRefreshTime then
high CamPwr
pause 500
low CamPwr
sleep 5
high CamPwr
pause 500
low CamPwr
sleep 1
CameraRefreshTimer = 0
pause 1000
endif
CDSTimer = CDSTimer + 1
If CDSTimer >= 2084 then ' check time every 2 1/2 minutes
high CdsPwr ' apply power to CDS sensor
nap 5 ' allow power to settle
readadc CdsIn, LightLevel
low CdsPwr
if LightLevel < NightSetting then
DayStatus = 0
else DayStatus = 1
CameraRefreshTimer = 0
CDSTimer = 0
if CameraOn = 1 then
high CamPwr
pause 500
low CamPwr
CameraOn = 0
endif
nap 2
goto main
endif
CDSTimer = 0
endif
endif
nap 2
goto main