EccentricDyslex
Newcomer
- Joined
- Jul 26, 2010
- Messages
- 11
Hi,
i am automating a home brewery, i have come up with the following code, can someone go over it and pick out why its not working?
Thanks!
i am automating a home brewery, i have come up with the following code, can someone go over it and pick out why its not working?
Thanks!
Visual Basic:
Public Class Form1
'Declare variables
Private selecteddate As Date
Private timeokpressed As Date
Private boilstartedtime As Date
Dim mashvolume As Integer
Dim boillength As Integer
Dim mashlength As Integer
Dim boilvolume As Integer
Dim differencebetweenmashvolumeandthirtyoneminutes As Integer
'digibee+ declare functions
Declare Function InitDgb Lib "dgb.dll" () As Boolean
Declare Function SetOutputs Lib "dgb.dll" (ByVal outputs As Integer) As Boolean
Declare Function ReadInputs Lib "dgb.dll" (ByRef inputs As Integer) As Boolean
Declare Function ReadAnalogueInputs Lib "dgb.dll" (ByRef aip1 As Integer, ByRef aip2 As Integer, ByRef aip3 As Integer, ByRef aip4 As Integer) As Boolean
Declare Function SetSensitivity Lib "dgb.dll" (ByVal HighNorm As Integer) As Boolean
Private Sub startimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStarttimer.Click
lblStatus.Text = "Waiting until it's 2 hours before requested mash-in time."
'inisialises digibee+ (removedfornow)
Do
If Date.Now.ToShortTimeString = selecteddate.AddHours(-2).ToShortTimeString Then
lblStatus.Text = "2 hours before mash-in time. Heating mash liquor. relay 1 on(HLTPID)" : Exit Do
'turns on output relay 1 to operate HLTPID setoutputs(1) (removed for now )
End If
Loop
Do
If Date.Now.ToShortTimeString = selecteddate.AddMinutes(-31).ToShortTimeString Then
lblStatus.Text = "31mins before mashin time, filling mash tun. relays 1 & 3 on (HLTPID & PP1)" : Exit Do
'Turns on output realys 1 & 3 to operate HLTPID & PP1 :setoutputs(3) (removed for now)
End If
Loop
Do
If Date.Now.ToShortTimeString = selecteddate.AddMinutes(-differencebetweenmashvolumeandthirtyoneminutes).ToShortTimeString Then lblStatus.Text = "waiting " & differencebetweenmashvolumeandthirtyoneminutes & " minutes which will then be mash in time." : Exit Do
'will keep relays 1&3 on until mashvolume has been pumped into mash tun
Loop
lblStatus.Text = "RIMs on" 'Turns on output realys 8,4,3 & 1 to operate HLTPID, MM1, V1 & MashPID :Setoutputs(282) (removed for now)
Do
If Date.Now.ToShortTimeString = selecteddate.ToShortTimeString Then
MsgBox("Ready for you to mash-in. Press ok when you have mashed in, topped up the HLT, fitted the RIMs manifold and filled the hop hoppers with hops as you require. Dont forget the protofloc!") : Exit Do
End If 'Notifies brewer that the mash tun is ready for mashing in. When OK is pressed program will move on to the next instruction.
Loop
timeokpressed = Now 'notes what time ok was pressed
Do
If Date.Now.ToShortTimeString = timeokpressed.AddMinutes(mashlength).ToShortTimeString Then lblStatus.Text = "Mash finished, starting sparge." : Exit Do
'waits for mashlength to expire
Loop
'setoutputs(19) when mashlength has expired, will open relays 5,2 and 1 thats pp1, pp2 and HLTPID and turn off MashPID and MM1 (removed for now)
Do
If Date.Now.ToShortTimeString = timeokpressed.AddMinutes(boilvolume).ToShortTimeString Then lblStatus.Text = "Turning off HLTPID to prevent run-dry."
: Exit Do ':setoutputs(100) turns off hltpid and on boilpid halfway through sparge as boiler is half full. 6,5 & 2 pp1, pp2 and boilpid on (removed for now)
Loop
Do
If Date.Now.ToShortTimeString = timeokpressed.AddMinutes(boilvolume * 2).ToShortTimeString Then lblStatus.Text = "Sparge complete, starting boil. Bittering hopper open."
: Exit Do ':setoutputs(1088) relays 10 & 6 open boilPID and bittering hops hopper opened. will close pp1, pp2 and hltpid relays(removed for now)
Loop
boilstartedtime = Now
Do
If Date.Now.ToShortTimeString = boilstartedtime.AddMinutes(boillength - 10).ToShortTimeString Then lblStatus.Text = "Opening 10 min hops hopper."
: Exit Do ':setoutputs(2112) relays 11&6 10min hopper & boilPID
Loop
Do
If Date.Now.ToShortTimeString = boilstartedtime.AddMinutes(boillength - 5).ToShortTimeString Then lblStatus.Text = "Opening 5 min hops hopper."
: Exit Do ':setoutputs(4160) relays 12&6 min hopper & boilPID
Loop
Do
If Date.Now.ToShortTimeString = boilstartedtime.AddMinutes(boillength).ToShortTimeString Then lblStatus.Text = "Opening 0 min hops hopper and stoping the boil."
: Exit Do ':setoutputs(8192) relay 13 ON 0 min hopper open and boilPId OFF
Loop
Do
If Date.Now.ToShortTimeString = boilstartedtime.AddMinutes(boillength + 5).ToShortTimeString Then lblStatus.Text = "Closing 0 min hops hopper, steeping for 15 minutes."
: Exit Do ':setoutputs(0) all relays off
Loop
Do
If Date.Now.ToShortTimeString = boilstartedtime.AddMinutes(boillength + 20).ToShortTimeString Then lblStatus.Text = "Aroma hop steep completed. Comencing wort cooling and transfer to fermentation vessel."
: Exit Do ':setoutputs(640) relays 7&9 on, PP3 and V2 on
Loop
Do
If Date.Now.ToShortTimeString = boilstartedtime.AddMinutes(boillength + 80).ToShortTimeString Then lblStatus.Text = "Wort transfer compeleted." : MsgBox("Your beer is ready for you to pitch the yeast!")
: Exit Do ':setoutputs(0) relays all off
Loop
Timertwohoursbeforemash.Interval = 60000
Timertwohoursbeforemash.Enabled = True
End Sub
Private Sub Timertwohoursbeforemash_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timertwohoursbeforemash.Tick
End Sub
Private Sub nudMashvolume_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudMashvolume.ValueChanged
mashvolume = nudMashvolume.Value
differencebetweenmashvolumeandthirtyoneminutes = (31 Mod mashvolume * 2)
End Sub
Private Sub nudBoilvolume_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudBoilvolume.ValueChanged
Boilvolume = nudBoilvolume.Value
End Sub
Private Sub nudBoillength_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudBoillength.ValueChanged
boillength = nudBoillength.Value
End Sub
Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
End Sub
Private Sub dtp1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtp1.ValueChanged
selecteddate = dtp1.Value
End Sub
End Class
Last edited by a moderator: