lbenson
Senior Member
Not cheap at $25 U.S., but this Sparkfun "IoT Power Relay" link came in my mailbox today: https://www.sparkfun.com/products/14236
Strictly it's Memory bytes, either EE... (Electrically Erasable..) or RA (Random Access) Memory. In most M2s, there is actually more than ten times more RAM than just the Variables b0 - b27 (it goes right up to 511) so you need to learn about PEEK/POKEs or the bptr (Byte Pointer). IMHO PEEK/POKE might be a little easier to understand, but @bptr is much more useful and powerful, so I'd recommend that.... do more homework on eeprom bytes ...variable ones b0-b27 is easiest and seem to get used up the fastest
The best way to think of it is as 256 bytes of RAM, locations numbered 0 to 255.I understand peek and poke but where it (data) gets stored is still confusing
lets say (in my training code)So all these will read RAM location 16 into 'b0' ...
b0 = b16
symbol byte_16 = b16
btye_16 = 16
poke 16, b0
;now b0 is 16 ? then i can use?
poke 120, b0
peek 120, b1
; so now b1 = b0 and ram 120 is still 16?
No ...Code:symbol byte_16 = b16 btye_16 = 16 poke 16, b0 ;now b0 is 16 ? then i can use?
The "16" specifies RAM location 16 and that is also "b16".Okay so now I am spinning around
so
"poke 16, b0 " ...so the ram location of "poke 16" is the same or not the same location of variable B16?
; testing code
start:
DO
b0 = 10
bPtr = 10
@bptr = b0
b0 = b0 + 10
poke 20,b0
b0 = b0 + 10
write 30,b0
read 30,b3
peek 20,b2
bPtr = 10
b1 = @bptr
; b1 = 10
; b2 = 20
; b3 = 30
debug
pause 1000
LOOP
Except that for the 18M2+, 14M2, and 20M2, ram extends up to address 511.,,, peek reads the data from a ram address up to 255 ...
b0 = 1
start:
bptr = 510
@bptr = b0 ; 510 ram = 1
b0 = b0 + 1
@bptrdec = b0 ; 509 ram = 2
b0 = b0 + 1
@bptrdec = b0 ; 508 ram = 3
b0 = b0 + 1
@bptrdec = b0 ; 507 ram = 4
b0 = b0 + 1
@bptrdec = b0 ; 506 ram = 5
bptr = 510
b1 = @bptr ; 510 , b1 = 2
b2 = @bptrdec ; 509 , b2 = 2
b3 = @bptrdec ; 508 , b3 = 3
b4 = @bptrdec ; 507 , b4 = 4
b5 = @bptrdec ; 506 , b5 = 5
debug
end
yes true thats exactly what i did works like perfectlyChange the first @bptr to @bptrdec to fix it.
The main thing is that '@bptr' variables and the like are not actually commands. Of course, 'time' isn't either but it does lend itself to being a single entry and is used often enough to justify its inclusion even though that is an anomaly.Problems like this would be much easier for beginners to solve if the online reference ( http://www.picaxe.com/BASIC-Commands/A-Z/ ) included all the 'active variables' like @bptrinc.
The main difference is that students and others may well be using the 'time' variable, but they are less likely to be doing advanced things like accessing RAM buffers and using '@bptr' variables.'Time' is in there, but I can't see what difference between 'Time' and '@bptrinc' determines why one is included in the list, but the other isn't.
#picaxe 20m2 'marks
#terminal 19200 " 4800 for M4 19200 for M16
SETFREQ M16 "M4 OR M16 time increments at 1 second
dirsB = %11111001
dirsC = %10111000
SYMBOL SensorTime = 12 ' seconds
SYMBOL LIGHTswitch = pinB.2
SYMBOL MOTIONsensor = pinB.1
SYMBOL SSRpower = outpinB.0
SYMBOL SSR = b0
SYMBOL secs = b1
SYMBOL mins = B2
SYMBOL hours = B3
SYMBOL date = B4 : SYMBOL day = B4 'day not used from RTC
SYMBOL month = B5
SYMBOL year = B6
SYMBOL CommonYear = b7 : SYMBOL Daylight = b7 : SYMBOL DL = b7
SYMBOL D0 = b8
SYMBOL D1 = b9
SYMBOL D2 = b10
SYMBOL D3 = b11
SYMBOL DayNumber = W6
SYMBOL DSTstart = w7
SYMBOL DSTend = w8 : SYMBOL DayS = w8
SYMBOL SunRise = W9
SYMBOL SunSet = W10
SYMBOL DayL = w11
"SETFREQ M32 copy paste error
TABLE 0,(204,203,202,199,194,189,182,174,166,156) ' Sunrise +240
TABLE 10,(147,136,126,115,105, 94, 83, 73, 63, 54) ' North Dakota
TABLE 20,( 45, 37, 29, 23, 18, 14, 11, 10, 10, 11) ' -7 StandardTime
TABLE 30,( 13, 17, 21, 26, 32, 38, 44, 51, 58, 64)
TABLE 40,( 71, 77, 84, 91, 97,104,111,118,125,133) ' 2018 (betweenleapyear)
TABLE 50,(140,148,156,163,171,178,185,191,196,200)
TABLE 60,(202,204)
TABLE 100,( 25, 30, 37, 44, 52, 60, 68, 76, 84, 92) ' Sunset +960
TABLE 110,(100,107,115,122,129,136,143,150,157,164)
TABLE 120,(171,178,185,191,197,203,207,211,214,215)
TABLE 130,(215,214,212,208,203,197,190,182,173,163)
TABLE 140,(153,143,132,121,110, 99, 89, 78, 68, 58)
TABLE 150,( 49, 41, 34, 27, 22, 18, 16, 15, 15, 17)
TABLE 160,( 21, 25)
InitialiseTime:
HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte ' Set to 100kbps
HI2Cout $0 , ( $30, $16, $19, 0 , $07 , $09 , $17) ' program with UTC/GMT -7 hours StandardTime
Main:
Switches: IF MOTIONsensor = 1 THEN : TIME = 0 : ENDIF
IF LIGHTswitch = 1 THEN : TIME = SensorTime -1 : ENDIF
IF LIGHTswitch = 0 THEN : SSR = 0 : ENDIF
Conditionals: IF TIME > SensorTime THEN : TIME = SensorTime : ENDIF
IF TIME < SensorTime THEN : SSR = 1 : ENDIF
HI2Cin $0 , (secs,mins,hours,day,date,month,year) ' Read DS1307 or DS3231
FOR bptr = 2 TO 6
@bptr = @bptr/$10*250+@bptr ' Convert BCD to Decimal
NEXT
MountainDaylightTime: ' United States
CommonYear = year //4 +3 /4 ' CommonYear =1
DayNumber = month +9 /12
DayNumber = CommonYear + DayNumber * DayNumber
DayNumber = month *275 /9 +date -30 -DayNumber
DayS = year *512 **46752 ' year =1 to 99
DSTstart = Days +72//7
DSTstart = 74 -CommonYear -DSTstart ' Second SunDay in March
DSTend = DSTstart +238 ' First SunDay in November
SunriseToSunset:
Daylight = Daynumber /6 : READtable Daylight,D0 : INC Daylight : READtable Daylight,D1
DayLight = DayLight +99 : READtable Daylight,D2 : INC Daylight : READtable Daylight,D3
DayLight = DayNumber //6 : IF D0 > D1 THEN : SWAP D0,D1 : DayLight = 6 -DayLight : ENDIF
SunRise = D1 -D0 * Daylight /6 +D0 +240
DayLight = DayNumber //6 : IF D2 > D3 THEN : SWAP D2,D3 : DayLight = 6 -DayLight : ENDIF
SunSet = D3 -D2 * Daylight /6 +D2 +960
DayL = hours *60 +mins : DL = 0
IF DayL > SunRise AND DayL < SunSet THEN : DL =1 : ENDIF
IF DayNumber < DSTstart OR DayNumber > DSTend THEN Display
IF DayNumber = DSTstart AND hours <2 THEN Display ' DST starts at 0200
IF DayNumber = DSTend AND hours >1 THEN Display ' DST ends at 0200
IF hours =23 THEN : INC date
IF month =4 or month =6 or month =9 and date =31 OR date=32 THEN : date =1 INC month: ENDIF
ENDIF : hours =hours +1//24 : Sunrise =Sunrise +60 : Sunset =Sunset +60
Sertxd ("MDT ") : GOTO DateTime ' DST +1
Display:Sertxd ("MST ") ' StandardTime
DateTime:
sertxd ("20",#year,"/",#month,"/",#date) ' Date 20yy/mm/dd
d3=mins/10
d2=mins//10
d1=secs/$10
d0=secs//$10
sertxd (" ",#hours,".",#d3,#d2,".",#d1,#d0) ' 24hr time hh/mm/ss
d2=sunrise/60
d1=sunrise//60 /10
d0=sunrise//60//10
Sertxd (" Sunrise ",#d2,":",#d1,#d0)
d2=sunset/60
d1=sunset//60 /10
d0=sunset//60//10
Sertxd (" Sunset ",#d2,":",#d1,#d0, cr,lf)
SSRcontrol: IF SSR = 0 THEN : SSRpower = 0 : ENDIF
IF SSR = 1 AND DL = 0 THEN : SSRpower = 1 : ENDIF
goto main
in order for me to do that (bug report) ...is to take 20 years of picaxe coding classeswont be posting too big of a bug report
Yes indeed, READ/WRITE and PEEK/POKE are very similar, but apply to different types of memory. Read/Write memory is EE (Electrically Erasable) or "non volatile", which means that it remains unchanged after cycling the power supply. This can be very useful, but EE memory has the disadvantage that it may eventually "wear out" if you make too many Writes (there is no limitation with Reading), so it should be used only for "suitable" purposes. The Program memory itself and also the "Table memory" in most PICAXEs are also EEPROM.does write and read in simple terms do the same but different locations of memory
so in example
poke 20, b0
write 20, b1
would this be two different locations of memory ?
symbol SECS = 30 ; Pointer into RAM
symbol MINS = 31
symbol HOURS = 32
symbol DATE = 33
symbol MONTH = 34
symbol YEAR = 35
........
peek HOURS, w0
if w0 > 23 then
poke HOURS,0
peek DATE,w0
inc w0
poke DATE,w0
endif
.......
bptr = HOURS
IF @bptr > 23 THEN
@bptrINC = 0 ; Reset the HOURS then move bptr to DATE [U]afterwards[/U]
@bptr = @bptr + 1 ; Increment the DATE
ENDIF
bptr = MONTH
IF @bptr = 4 OR @bptr = 6 OR @bptrtDEC= 9 AND @bptr = 31 OR @bptr = 32 THEN
@bptrINC = 1 ; Reset the DATE then move bptr to MONTH [U]afterwards[/U]
INC @bptr ; Increment the MONTH
ENDIF
I am actually seeing dim light in the tunnel (maybe another train) but I keep going back in forthso I'm pleased to see that you're getting to grips with @bptr
According to the Microchip data sheet the typical expected time is 40 years, but it's probably more in practice.If I use write to save data will the data be lost if there is no power to the picaxe for a specific time ..I.E. 10 minutes ...10 days ?
#picaxe 20m2 'marks
#terminal 4800
SETFREQ M4 ' OR M4 time 1 second
dirsB = %11111001
dirsC = %10111000
SYMBOL SensorTime = 12 ' seconds
SYMBOL LIGHTswitch = pinb.2
SYMBOL MOTIONsensor = pinb.1
SYMBOL SSRpower = outpinb.0
SYMBOL SSR = b0
SYMBOL secs = b1
SYMBOL mins = B2
SYMBOL hours = B3
SYMBOL date = B4 : SYMBOL day = B4 'day not used from RTC
SYMBOL month = B5
SYMBOL year = B6
SYMBOL CommonYear = b7 : SYMBOL Daylight = b7 : SYMBOL DL = b7
SYMBOL D0 = b8
SYMBOL D1 = b9
SYMBOL D2 = b10
SYMBOL D3 = b11
SYMBOL DayNumber = W6
SYMBOL DSTstart = w7
SYMBOL DSTend = w8 : SYMBOL DayS = w8
SYMBOL SunRise = W9
SYMBOL SunSet = W10
SYMBOL DayL = w11
'SETFREQ M32 <-- had this ignored
#picaxe 20m2 'marks
#terminal 38400
SETFREQ M32 ' time increments 0.5 seconds
dirsB = %11111001
dirsC = %10111000
SYMBOL SensorTime = 12 ' so will be 6 seconds
SYMBOL LIGHTswitch = pinB.2
SYMBOL MOTIONsensor = pinB.1
SYMBOL SSRpower = outpinB.0
SYMBOL SSR = b0
SYMBOL secs = b1
SYMBOL mins = B2
SYMBOL hours = B3
SYMBOL date = B4 : SYMBOL day = B4 'day not used from RTC
SYMBOL month = B5
SYMBOL year = B6
SYMBOL CommonYear = b7 : SYMBOL Daylight = b7 : SYMBOL DL = b7
SYMBOL D0 = b8
SYMBOL D1 = b9
SYMBOL D2 = b10
SYMBOL D3 = b11
SYMBOL DayNumber = W6
SYMBOL DSTstart = w7
SYMBOL DSTend = w8 : SYMBOL DayS = w8
SYMBOL SunRise = W9
SYMBOL SunSet = W10
SYMBOL DayL = w11
SYMBOL CRC = b24
TABLE 0,(204,203,202,199,194,189,182,174,166,156) ' Sunrise +240
TABLE 10,(147,136,126,115,105, 94, 83, 73, 63, 54) ' North Dakota
TABLE 20,( 45, 37, 29, 23, 18, 14, 11, 10, 10, 11) ' -7 StandardTime
TABLE 30,( 13, 17, 21, 26, 32, 38, 44, 51, 58, 64)
TABLE 40,( 71, 77, 84, 91, 97,104,111,118,125,133) ' 2018 (betweenleapyear)
TABLE 50,(140,148,156,163,171,178,185,191,196,200)
TABLE 60,(202,204)
TABLE 100,( 25, 30, 37, 44, 52, 60, 68, 76, 84, 92) ' Sunset +960
TABLE 110,(100,107,115,122,129,136,143,150,157,164)
TABLE 120,(171,178,185,191,197,203,207,211,214,215)
TABLE 130,(215,214,212,208,203,197,190,182,173,163)
TABLE 140,(153,143,132,121,110, 99, 89, 78, 68, 58)
TABLE 150,( 49, 41, 34, 27, 22, 18, 16, 15, 15, 17)
TABLE 160,( 21, 25)
InitialiseTime:
HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte ' Set to 100kbps
HI2Cout $0 , ( $30, $16, $19, 0 , $07 , $09 , $17) ' program with UTC/GMT -7 hours StandardTime
Main:
Switches: IF MOTIONsensor = 1 THEN : TIME = 0 : ENDIF
IF LIGHTswitch = 1 THEN : TIME = SensorTime -1 : ENDIF
IF LIGHTswitch = 0 THEN : SSR = 0 : ENDIF
Conditionals: IF TIME > SensorTime THEN : TIME = SensorTime : ENDIF
IF TIME < SensorTime THEN : SSR = 1 : ENDIF
HI2Cin $0 , (secs,mins,hours,day,date,month,year) ' Read DS1307 or DS3231
FOR bptr = 2 TO 6
@bptr = @bptr/$10*250+@bptr ' Convert BCD to Decimal
NEXT
MountainDaylightTime: ' United States
CommonYear = year //4 +3 /4 ' CommonYear =1
DayNumber = month +9 /12
DayNumber = CommonYear + DayNumber * DayNumber
DayNumber = month *275 /9 +date -30 -DayNumber
DayS = year *512 **46752 ' year =1 to 99
DSTstart = Days +72//7
DSTstart = 74 -CommonYear -DSTstart ' Second SunDay in March
DSTend = DSTstart +238 ' First SunDay in November
SunriseToSunset:
Daylight = Daynumber /6 : READtable Daylight,D0 : INC Daylight : READtable Daylight,D1
DayLight = DayLight +99 : READtable Daylight,D2 : INC Daylight : READtable Daylight,D3
DayLight = DayNumber //6 : IF D0 > D1 THEN : SWAP D0,D1 : DayLight = 6 -DayLight : ENDIF
SunRise = D1 -D0 * Daylight /6 +D0 +240
DayLight = DayNumber //6 : IF D2 > D3 THEN : SWAP D2,D3 : DayLight = 6 -DayLight : ENDIF
SunSet = D3 -D2 * Daylight /6 +D2 +960
DayL = hours *60 +mins : DL = 0
IF DayL > SunRise AND DayL < SunSet THEN : DL =1 : ENDIF
IF DayNumber < DSTstart OR DayNumber > DSTend THEN Display
IF DayNumber = DSTstart AND hours <2 THEN Display ' DST starts at 0200
IF DayNumber = DSTend AND hours >1 THEN Display ' DST ends at 0200
IF hours =23 THEN : INC date
IF month =4 or month =6 or month =9 and date =31 OR date=32 THEN : date =1 INC month: ENDIF
ENDIF : hours =hours +1//24 : Sunrise =Sunrise +60 : Sunset =Sunset +60
d0="D" : GOTO DateTime ' DST +1
Display: d0= "S" ' StandardTime
DateTime:
IF secs <> CRC THEN ' wait for change of secs
Sertxd ("M",d0,"T ")
sertxd ("20",#year,"/",#month,"/",#date) ' Date 20yy/mm/dd
d3=mins/10
d2=mins//10
d1=secs/$10
d0=secs//$10
sertxd (" ",#hours,".",#d3,#d2,".",#d1,#d0) ' 24hr time hh/mm/ss
d2=sunrise/60
d1=sunrise//60 /10
d0=sunrise//60//10
Sertxd (" Sunrise ",#d2,":",#d1,#d0)
d2=sunset/60
d1=sunset//60 /10
d0=sunset//60//10
Sertxd (" Sunset ",#d2,":",#d1,#d0, cr,lf)
ENDIF : CRC = secs
SSRcontrol: IF SSR = 0 THEN : SSRpower = 0 : ENDIF
IF SSR = 1 AND DL = 0 THEN : SSRpower = 1 : ENDIF
goto main
No they're not the same, but it's more the "numbers" themselves than the memory type. In computing there are (at least) two different types of numbers called "variables" and "constants"."poke HOURS,0"
that is the same as
poke HOURS,B0 ?
#picaxe 20m2 'marks
#terminal 38400
SETFREQ M32 ' time increments 0.5 seconds
dirsB = %11111001
dirsC = %10111000
SYMBOL SensorTime = 12 ' so will be 6 seconds
SYMBOL LIGHTswitch = pinB.2
SYMBOL MOTIONsensor = pinB.1
SYMBOL SSRpower = outpinB.0
SYMBOL MSR = b0
SYMBOL secs = b1
SYMBOL mins = B2
SYMBOL hours = B3
SYMBOL date = B4 : SYMBOL day = B4 'day not used from RTC
SYMBOL month = B5
SYMBOL year = B6
SYMBOL CommonYear = b7 : SYMBOL Daylight = b7 : SYMBOL MFL = b7
SYMBOL D0 = b8
SYMBOL D1 = b9
SYMBOL D2 = b10
SYMBOL D3 = b11
SYMBOL DayNumber = W6
SYMBOL DSTstart = w7
SYMBOL DSTend = w8 : SYMBOL DayS = w8 : SYMBOL SunrisePlus10 = w8
SYMBOL SunRiseTake60 = w9 : SYMBOL Sunrise = w9
SYMBOL SunSet = W10
SYMBOL DayTime = w11
SYMBOL CRC = b24
SYMBOL AON = b25
TABLE 0,(204,203,202,199,194,189,182,174,166,156) ' Sunrise +240 minutes
TABLE 10,(147,136,126,115,105, 94, 83, 73, 63, 54) ' North Dakota
TABLE 20,( 45, 37, 29, 23, 18, 14, 11, 10, 10, 11) ' -7 StandardTime
TABLE 30,( 13, 17, 21, 26, 32, 38, 44, 51, 58, 64)
TABLE 40,( 71, 77, 84, 91, 97,104,111,118,125,133) ' 2018 (betweenleapyear)
TABLE 50,(140,148,156,163,171,178,185,191,196,200)
TABLE 60,(202,204)
TABLE 100,( 25, 30, 37, 44, 52, 60, 68, 76, 84, 92) ' Sunset +960 minutes
TABLE 110,(100,107,115,122,129,136,143,150,157,164)
TABLE 120,(171,178,185,191,197,203,207,211,214,215)
TABLE 130,(215,214,212,208,203,197,190,182,173,163)
TABLE 140,(153,143,132,121,110, 99, 89, 78, 68, 58)
TABLE 150,( 49, 41, 34, 27, 22, 18, 16, 15, 15, 17)
TABLE 160,( 21, 25)
InitialiseTime:
HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte ' Set to 100kbps
HI2Cout $0 , ( $30, $22, $04, 0 , $07 , $09 , $17) ' program with UTC/GMT -7 hours StandardTime
Main:
Switches: IF MOTIONsensor = 1 THEN : TIME = 0 : ENDIF
IF LIGHTswitch = 1 THEN : TIME = SensorTime -1 : ENDIF
IF LIGHTswitch = 0 THEN : MSR = 0 : ENDIF
SSRconditionals1: IF TIME > SensorTime THEN : TIME = SensorTime : ENDIF
IF TIME < SensorTime THEN : MSR = 1 : ENDIF
HI2Cin $0 , (secs,mins,hours,day,date,month,year) ' Read DS1307 or DS3231
FOR bptr = 2 TO 6
@bptr = @bptr/$10*250+@bptr ' Convert BCD to Decimal
NEXT
MountainDaylightTime: ' United States
CommonYear = year //4 +3 /4 ' CommonYear =1
DayNumber = month +9 /12
DayNumber = CommonYear + DayNumber * DayNumber
DayNumber = month *275 /9 +date -30 -DayNumber
DayS = year *512 **46752 ' year =1 to 99
DSTstart = Days +72//7
DSTstart = 74 -CommonYear -DSTstart ' Second SunDay in March
DSTend = DSTstart +238 ' First SunDay in November
SunriseToSunset:
Daylight = Daynumber /6 : READtable Daylight,D0 : INC Daylight : READtable Daylight,D1
DayLight = DayLight +99 : READtable Daylight,D2 : INC Daylight : READtable Daylight,D3
DayLight = DayNumber //6 : IF D0 > D1 THEN : SWAP D0,D1 : DayLight = 6 -DayLight : ENDIF
SunRiseTake60 = D1 -D0 * Daylight /6 +D0 +180
DayLight = DayNumber //6 : IF D2 > D3 THEN : SWAP D2,D3 : DayLight = 6 -DayLight : ENDIF
SunSet = D3 -D2 * Daylight /6 +D2 +960
IF DayNumber < DSTstart OR DayNumber > DSTend THEN Display
IF DayNumber = DSTstart AND hours <2 THEN Display ' DST starts at 0200
IF DayNumber = DSTend AND hours >1 THEN Display ' DST ends at 0200
IF hours =23 THEN : INC date
IF month =4 or month =6 or month =9 and date =31 OR date=32 THEN : date =1 INC month: ENDIF
ENDIF : hours =hours +1//24 : Sunrise =Sunrise +60 : Sunset =Sunset +60
d0="D" : GOTO SSRconditionals2: ' DST +1
Display: d0= "S" ' StandardTime
SSRconditionals2:DayTime = hours *60 +mins '' DayTime (total minutes of day)
MFL=0 :IF DayTime < SunriseTake60 THEN : MFL =1 : ENDIF
AON=0 :IF DayTime > Sunset THEN : AON =1 : ENDIF : SunRisePlus10 = SunriseTake60 +70
IF DayTime > SunriseTake60 AND Daytime < SunRisePlus10 THEN : AON=1 : ENDIF
IF secs <> CRC THEN ' wait for change of secs
Sertxd ("M",d0,"T ")
sertxd ("20",#year,"/",#month,"/",#date) ' Date 20yy/mm/dd
d3=mins/10
d2=mins//10
d1=secs/$10
d0=secs//$10
sertxd (" ",#hours,".",#d3,#d2,".",#d1,#d0) ' 24hr time hh/mm/ss
sunrise = SunriseTake60 +60
d2=sunrise/60
d1=sunrise//60 /10
d0=sunrise//60//10
Sertxd (" Sunrise ",#d2,":",#d1,#d0)
d2=sunset/60
d1=sunset//60 /10
d0=sunset//60//10
Sertxd (" Sunset ",#d2,":",#d1,#d0, cr,lf)
ENDIF : CRC = secs
SSRcontrol: IF MSR = 0 AND AON = 0 THEN : SSRpower = 0 : ENDIF ' MotionSenseRelay AlwaysON
IF MSR = 1 AND MFL = 1 OR AON = 1 THEN : SSRpower = 1 : ENDIF 'MidnighttoFirstLight
goto main
#picaxe 20m2 'marks
#terminal 38400
SETFREQ M32 ' time increments 0.5 seconds
dirsB = %11111001
dirsC = %10111000
SYMBOL SensorTime = 12 ' so will be 6 seconds
SYMBOL LIGHTswitch = pinB.2
SYMBOL MOTIONsensor = pinB.1
SYMBOL SSRpower = outpinB.0
SYMBOL MSR = b0
SYMBOL secs = b1
SYMBOL mins = B2
SYMBOL hours = B3
SYMBOL date = B4 : SYMBOL day = B4 'day not used from RTC
SYMBOL month = B5
SYMBOL year = B6
SYMBOL CommonYear = b7 : SYMBOL Daylight = b7 : SYMBOL MFL = b7
SYMBOL D0 = b8
SYMBOL D1 = b9
SYMBOL D2 = b10
SYMBOL D3 = b11
SYMBOL DayNumber = W6
SYMBOL DSTstart = w7
SYMBOL DSTend = w8 : SYMBOL DayS = w8 : SYMBOL SunrisePlus10 = w8
SYMBOL SunRiseTake60 = w9 : SYMBOL Sunrise = w9
SYMBOL SunSet = W10
SYMBOL DayTime = w11
SYMBOL CRC = b24
SYMBOL AON = b25
TABLE 0,(204,203,202,199,194,189,182,174,166,156) ' Sunrise +240 minutes
TABLE 10,(147,136,126,115,105, 94, 83, 73, 63, 54) ' North Dakota
TABLE 20,( 45, 37, 29, 23, 18, 14, 11, 10, 10, 11) ' -7 StandardTime
TABLE 30,( 13, 17, 21, 26, 32, 38, 44, 51, 58, 64)
TABLE 40,( 71, 77, 84, 91, 97,104,111,118,125,133) ' 2018 (betweenleapyear)
TABLE 50,(140,148,156,163,171,178,185,191,196,200)
TABLE 60,(202,204)
TABLE 100,( 25, 30, 37, 44, 52, 60, 68, 76, 84, 92) ' Sunset +960 minutes
TABLE 110,(100,107,115,122,129,136,143,150,157,164)
TABLE 120,(171,178,185,191,197,203,207,211,214,215)
TABLE 130,(215,214,212,208,203,197,190,182,173,163)
TABLE 140,(153,143,132,121,110, 99, 89, 78, 68, 58)
TABLE 150,( 49, 41, 34, 27, 22, 18, 16, 15, 15, 17)
TABLE 160,( 21, 25)
InitialiseTime:
HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte ' Set to 100kbps
HI2Cout $0 , ( $30, $20, $04, 0 , $13 , $09 , $17) ' program with UTC/GMT -7 hours StandardTime
TIME = SensorTime ''' remove sensortime out when first powering on during MFL
Main:
Switches: IF MOTIONsensor = 1 THEN : TIME = 0 : ENDIF
IF LIGHTswitch = 1 THEN : TIME = SensorTime -1 : ENDIF
IF LIGHTswitch = 0 THEN : MSR = 0 : ENDIF
SSRconditionals1: IF TIME > SensorTime THEN : TIME = SensorTime : ENDIF
IF TIME < SensorTime THEN : MSR = 1 : ENDIF
HI2Cin $0 , (secs,mins,hours,day,date,month,year) ' Read DS1307 or DS3231
FOR bptr = 2 TO 6
@bptr = @bptr/$10*250+@bptr ' Convert BCD to Decimal
NEXT
MountainDaylightTime: ' United States
CommonYear = year //4 +3 /4 ' CommonYear =1
DayNumber = month +9 /12
DayNumber = CommonYear + DayNumber * DayNumber
DayNumber = month *275 /9 +date -30 -DayNumber
DayS = year *512 **46752 ' year =1 to 99
DSTstart = Days +72//7
DSTstart = 74 -CommonYear -DSTstart ' Second SunDay in March
DSTend = DSTstart +238 ' First SunDay in November
SunriseToSunset:
Daylight = Daynumber /6 : READtable Daylight,D0 : INC Daylight : READtable Daylight,D1
DayLight = DayLight +99 : READtable Daylight,D2 : INC Daylight : READtable Daylight,D3
DayLight = DayNumber //6 : IF D0 > D1 THEN : SWAP D0,D1 : DayLight = 6 -DayLight : ENDIF
SunRiseTake60 = D1 -D0 * Daylight /6 +D0 +180
DayLight = DayNumber //6 : IF D2 > D3 THEN : SWAP D2,D3 : DayLight = 6 -DayLight : ENDIF
SunSet = D3 -D2 * Daylight /6 +D2 +960
IF DayNumber < DSTstart OR DayNumber > DSTend THEN Display
IF DayNumber = DSTstart AND hours <2 THEN Display ' DST starts at 0200
IF DayNumber = DSTend AND hours >1 THEN Display ' DST ends at 0200
IF hours =23 THEN : INC date
IF month =4 or month =6 or month =9 and date =31 OR date=32 THEN : date =1 INC month: ENDIF
ENDIF : hours =hours +1//24 : Sunrise =Sunrise +60 : Sunset =Sunset +60
d0="D" : GOTO SSRconditionals2: ' DST +1
Display: d0= "S" ' StandardTime
SSRconditionals2:DayTime = hours *60 +mins '' (moved) DayTime total minutes of day
MFL=0 :IF DayTime < SunriseTake60 THEN : MFL =1 : ENDIF
AON=0 :IF DayTime => Sunset THEN : AON =1 : ENDIF : SunRisePlus10 = SunriseTake60 +70 ''' (=)
IF DayTime >= SunriseTake60 AND Daytime < SunRisePlus10 THEN : AON=1 : ENDIF ''' (=)
IF secs <> CRC THEN ' wait for change of secs
Sertxd ("M",d0,"T ")
sertxd ("20",#year,"/",#month,"/",#date) ' Date 20yy/mm/dd
d3=mins/10
d2=mins//10
d1=secs/$10
d0=secs//$10
sertxd (" ",#hours,".",#d3,#d2,".",#d1,#d0) ' 24hr time hh/mm/ss
sunrise = SunriseTake60 +60
d2=sunrise/60
d1=sunrise//60 /10
d0=sunrise//60//10
Sertxd (" Sunrise ",#d2,":",#d1,#d0)
d2=sunset/60
d1=sunset//60 /10
d0=sunset//60//10
Sertxd (" Sunset ",#d2,":",#d1,#d0, cr,lf)
ENDIF : CRC = secs
SSRcontrol: IF MSR = 0 or MFL = 0 AND AON = 0 THEN : SSRpower = 0 : ENDIF ''' ( or MFL=0) MotionSenseRelay AlwaysON
IF MSR = 1 AND MFL = 1 OR AON = 1 THEN : SSRpower = 1 : ENDIF ' MidnighttoFirstLight
goto main
Do
Gosub CheckPir
Gosub CheckDaylightTimes
If pirActivated = 1 And isDayTime = 0 Then
Gosub LightOn
Gosub StartTimeout
End If
If LightIsOn = 1 And timedOut = 1 Then
Gosub LightOff
End If
Loop
I think we all did, and those who have not simply have that to comelearned the hard way, tom
I do that alot outside real world.."learned the hardway"
When I first started learning to code a picaxe I explained every line with 'and a noteCertainly you can overdo it and end up typing a lot