picaxester
Senior Member
Heres an analog data logger program that I'm working on. It's not finished and still needs a lot of work.
It uses FreeBASIC and a PICAXE 08M to read three analog voltages and then sends them to my pc through the serial port.
Video
FB code:
PICAXE code:
It uses FreeBASIC and a PICAXE 08M to read three analog voltages and then sends them to my pc through the serial port.
Video
FB code:
Code:
dim as integer x, y, buttons, i, ii, ra1, ra2, rb1, rb2, rc1, rc2, graphpos
dim as double logtime
dim as string s, text, filename, temp, device_name, ra1s, ra2s, rb1s, rb2s, rc1s, rc2s
declare sub bttn(x as integer, y as integer, s as string)
declare sub buttonup(x as integer, y as integer, s as integer)
declare sub buttondown(x as integer, y as integer, s as integer)
declare sub inbox(x as integer, y as integer, w as integer, h as integer)
declare sub clearbox(x as integer, y as integer)
declare sub label(x as integer, y as integer, s as string)
screenres 800,335
color 0, 15
cls
bttn (555, 14, "START") 'Button #1
bttn (619, 14, "STOP") 'Button #2
bttn (675, 14, "CLEAR") 'Button #3
bttn (739, 14, "EXIT") 'Button #4
inbox (51, 14, 163, 26) 'In/Out box #1
inbox (275, 14, 51, 26) 'In/Out box #2
locate 4, 37: color 0,15: print "mins"
inbox (403, 14, 131, 26) 'In/Out box #3
locate 4, 52: color 0,15
#IFDEF __FB_LINUX__
print "/dev/ttyS0"
#ENDIF
#IFDEF __FB_WIN32__
print "COM1"
#ENDIF
#IFDEF __FB_DOS__
print "COM1"
#ENDIF
inbox (11, 54, 771, 269) 'In/Out box #4 314
label (11, 16, "FILE") 'Label #1
label (11, 32, "NAME") 'Label #2
label (235, 16, "LOG") 'Label #3
label (235, 32, "TIME") 'Label #4
label (347, 16, "DEVICE") 'Label #5
label (347, 32, "NAME") 'Label #6
for y = 61 to 330 step 15
line (14, y)-(783, y), 7
next y
logtime = 1
graphpos = 14
device_name = "/dev/ttyS0"
do
do while buttons < 1
getmouse (x, y, , buttons)
s = inkey$
if s = chr(255) & "k" or s = chr(27) then end
sleep 10
loop
'BUTTONS========================================================
'START
if x > 555 and x < 609 and y > 14 and y < 44 then
buttondown (558, 43, 50)
open filename & ".txt" for binary as #1
#IFDEF __FB_LINUX__
shell "stty -F " & device_name & " speed 4800"
Open Com device_name & ":4800,n,8,1,CD,CS,DS,RS,BIN" For Binary As #2
#ENDIF
#IFDEF __FB_WIN32__
Open Com device_name & ":4800,n,8,1,CD,CS,DS,RS,BIN" For Binary As #2
#ENDIF
#IFDEF __FB_DOS__
Open Com device_name & ":4800,n,8,1,CD,CS,DS,RS,BIN" For Binary As #2
#ENDIF
ra2 = 316
rb2 = 316
rc2 = 316
'print #2, "B"
sleep 100, 1
for i = graphpos to 784 'step 5
print #2, chr(66)
sleep 40, 1
ra1 = val(Input(LOC(1), 2))
print #2, chr(82)
sleep 40, 1
rb1 = val(Input(LOC(1), 2))
print #2, chr(71)
sleep 40, 1
rc1 = val(Input(LOC(1), 2))
if ra1 > 255 or ra1 < 0 then ra1 = 0
if rb1 > 255 or rb1 < 0 then rb1 = 0
if rc1 > 255 or rc1 < 0 then rc1 = 0
print #1, ra1 & " Blue"
print #1, rb1 & " Red"
print #1, rc1 & " Green"
ra1 = 316 - ra1
rb1 = 316 - rb1
rc1 = 316 - rc1
if ra2 > 316 or ra2 < 61 then ra2 = 316
if rb2 > 316 or rb2 < 61 then rb2 = 316
if rc2 > 316 or rc2 < 61 then rc2 = 316
line (i, ra1)-(i - 1, ra2), 1
line (i, rb1)-(i - 1, rb2), 4
line (i, rc1)-(i - 1, rc2), 2
ra2 = ra1
rb2 = rb1
rc2 = rc1
for ii = 1 to logtime
getmouse (x, y, , buttons)
if x > 619 and x < 665 and y > 14 and y < 44 and buttons = 1 then
graphpos = i
exit for, for
end if
if x > 675 and x < 729 and y > 14 and y < 44 and buttons = 1 then goto cleargraph
if x > 739 and x < 785 and y > 14 and y < 44 and buttons = 1 then end
sleep 20, 1
next ii
next i
close #1
close #2
'STOP
elseif x > 619 and x < 665 and y > 14 and y < 44 then
buttondown (622, 43, 42)
'CLEAR
elseif x > 675 and x < 729 and y > 14 and y < 44 then
cleargraph:
buttondown (678, 43, 50)
clearbox (14, 57)
graphpos = 14
for y = 61 to 330 step 15
line (14, y)-(783, y), 7
next y
close #1
close #2
kill filename & ".txt"
'EXIT
elseif x > 739 and x < 785 and y > 14 and y < 44 then
buttondown (742, 43, 42)
close #1
close #2
end
'IN/OUT BOXES===================================================
'Box #1
elseif x > 51 and x < 218 and y > 14 and y < 43 then
clearbox (54, 17)
clearbox (14, 57)
graphpos = 14
for y = 61 to 330 step 15
line (14, y)-(783, y), 7
next y
locate 4, 8: color 0,15: print "_"
filename = ""
do
getmouse (x, y, , buttons)
if buttons > 0 and x < 51 or buttons > 0 and x > 218 or buttons > 0 and y < 14 or buttons > 0 and y > 43 then exit do
s = inkey$
if s = chr(255) & "k" or s = chr(27) then end
if s = chr(13) then exit do
if s = chr(8) and len(filename) > 1 then
clearbox (54, 17)
filename = left(filename, len(filename))
locate 4, 8: color 0,15: print filename & "_"
end if
if s > "" and len(filename) < 19 then
clearbox (54, 17)
filename = filename + s
locate 4, 8: color 0,15: print filename & "_"
end if
sleep 20
loop
clearbox (54, 17)
locate 4, 8: color 0,15: print filename
close #1
open filename & ".txt" for binary as #1
if lof(1) > 0 Then
for i = 14 to 784 'step 5
line input #1, ra1s
line input #1, rb1s
line input #1, rc1s
ra1 = val(ra1s)
rb1 = val(rb1s)
rc1 = val(rc1s)
if ra1 > 255 or ra1 < 0 then ra1 = 0
if rb1 > 255 or rb1 < 0 then rb1 = 0
if rc1 > 255 or rc1 < 0 then rc1 = 0
ra1 = 316 - ra1
rb1 = 316 - rb1
rc1 = 316 - rc1
if ra2 > 316 or ra2 < 61 then ra2 = 316
if rb2 > 316 or rb2 < 61 then rb2 = 316
if rc2 > 316 or rc2 < 61 then rc2 = 316
line (i, ra1)-(i - 1, ra2), 1
line (i, rb1)-(i - 1, rb2), 4
line (i, rc1)-(i - 1, rc2), 2
ra2 = ra1
rb2 = rb1
rc2 = rc1
next i
else
clearbox (14, 57)
for y = 61 to 330 step 15
line (14, y)-(783, y), 7
next y
end if
'Box #2
elseif x > 275 and x < 330 and y > 14 and y < 43 then
clearbox (278, 17)
locate 4, 36: color 0,15: input "", logtime
logtime = logtime * 60
logtime = int(logtime * .18)
'Box #3
elseif x > 403 and x < 538 and y > 14 and y < 43 then
clearbox (406, 17)
close #2
locate 4, 52: color 0,15: input "", device_name
'Box #4
elseif x > 11 and x < 786 and y > 54 and y < 371 then
'clearbox (14, 57)
'locate 9, 3: color 0,15: print "???"
end if
sleep 10
getmouse (x, y, , buttons)
do while x > 1 and buttons > 0: getmouse (x, y, , buttons): sleep 10: loop
buttonup (556,39,50)
buttonup (620,39,42)
buttonup (676,39,50)
buttonup (740,39,42)
loop
sub bttn(x as integer, y as integer, s as string)
dim as integer w
w = len(s) * 8 + 10
draw string (x + 8, y + 10), s
draw "C0 BM" & x & "," & y & "D26 R D R D R" & w & "U R U R U26 L U L U L" & w & "D L D L C7 BM" & x + 1 & "," & y + 1 & "BD26 BR BD BR BD R" & w & "U R U R U26 C0"
end sub
sub buttonup(x as integer, y as integer, w as integer)
draw "C15 BM" & x & "," & y & "U24 R U R U R" & w - 2 & "C7 BM" & x + 2 & "," & y + 4 & "R" & w & "U R U R U26"
end sub
sub buttondown(x as integer, y as integer, w as integer)
draw "C15 BM" & x & "," & y & " R " & w & " U R U R U26 C7 BM" & x - 2 & "," & y - 4 & " U24 R U R U R" & w - 2
end sub
sub inbox(x as integer, y as integer, w as integer, h as integer)
draw "C0 BM" & x & "," & y & " D" & h & " R D R D R" & w & " U R U R U" & h & " L U L U L" & w & " D L D L C7 BM" & x + 1 & "," & y + 1 & " D" & h - 2 & " R D R D R" & w - 2 & " U R U R U" & h - 2 & " L U L U L" & w - 2 & "D L D"
end sub
sub clearbox(x as integer, y as integer)
draw "BM" & x & "," & y & "P15,7 C0"
end sub
sub label(x as integer, y as integer, s as string)
draw string (x, y), s, 0
end sub
Code:
setfreq m8
do
serin 3, N2400, b0
if b0 = "B" then
readadc 1, b1
serout 0, N2400, (#b1)
elseif b0 = "R" then
readadc 2, b2
serout 0, N2400, (#b2)
elseif b0 = "G" then
readadc 4, b3
serout 0, N2400, (#b3)
endif
loop