Bigginer's Question .. Will this work?
hjlee918
Posts: 8
Hi,
I'm trying to program for single button to toggle for discrete power function. I would appreciate if you take a look at the code and see if this works.
DEFINE_CONSTANT
INTEGER Proj_Off = 0
INTEGER Proj_On = 1
DEFINE_VARIABLE
INTEGER nProjPwr // Track Projector Status
DEFINE_FUNCTION ProjPwrOn()
{
PULSE[dvProj,27]
WAIT 50
{
nProjPwr = Proj_On
}
}
DEFINE_FUNCTION ProjPwrOff()
{
PULSE[dvProj,28]
WAIT 50
{
nProjPwr = Proj_Off
}
}
DEFINE_EVENT
BUTTON_EVENT[dvTP_Proj,9] // The projector power toggle button
{
PUSH:
{
IF(![dvTP_Proj,9])
{
ProjPwrOn()
}
ELSE
{
ProjPwrOff()
}
}
}
DEFINE_PROGRAM
[dvTP_Proj,9] = ![dvTP_Proj,9] // Toggle Projector Power button
I'm trying to program for single button to toggle for discrete power function. I would appreciate if you take a look at the code and see if this works.
DEFINE_CONSTANT
INTEGER Proj_Off = 0
INTEGER Proj_On = 1
DEFINE_VARIABLE
INTEGER nProjPwr // Track Projector Status
DEFINE_FUNCTION ProjPwrOn()
{
PULSE[dvProj,27]
WAIT 50
{
nProjPwr = Proj_On
}
}
DEFINE_FUNCTION ProjPwrOff()
{
PULSE[dvProj,28]
WAIT 50
{
nProjPwr = Proj_Off
}
}
DEFINE_EVENT
BUTTON_EVENT[dvTP_Proj,9] // The projector power toggle button
{
PUSH:
{
IF(![dvTP_Proj,9])
{
ProjPwrOn()
}
ELSE
{
ProjPwrOff()
}
}
}
DEFINE_PROGRAM
[dvTP_Proj,9] = ![dvTP_Proj,9] // Toggle Projector Power button
0
Comments
The only thing I really would change is the way to use the projector's state It is the better way to use the projector state variable instead of the channel of the Touchpanel button, because if the projector is tracked as ON, and the panel goes offline and online again later, the channel is off, and so the toggle will fail.
In your code, nProjPwr didn't get used, and the last line would have caused the power button to change states every run through mainline.
There are lots of reasons not to code it this way too by the way. Your status tracking can get screwed up for any number of reasons, then you'll be out of sync and your control system won't look very intelligent anymore. Also, most projectors have warmup/cooldown periods where it doesn't accept commands. You'll need to try to account for those too.
--John
Ups..... you are right, not seen (1 big cup of coffee still did not bring me fully online this morning )
Thnaks all for your help.
I've attended the prog.I class and this was part of the final project assignment for us to try out.
I don't agree with this way of programming either, but it just serves the practice purpose, I guess.
John