How to get Lights to stop flickering
Author |
Message |
jSong
|
Posted: Fri May 24, 2013 9:30 am Post subject: How to get Lights to stop flickering |
|
|
What is it you are trying to achieve?
I am trying to have my so-called loft lights turn on when pressing assigned buttons.
This is for my summative assignment.
This is also my first time programming EVER. So sorry if it is messy and I made a lot of stupid mistakes !
What is the problem you are having?
Well, my issue here is that I am trying to have both lights turn on when I press the assigned key 'd'. The issue is that it keeps on flickering as to the rest of my commands (A and D) that are working fine. Basically I am trying to ask how do I prevent this and I would actually like to know why this is happening .
Describe what you have tried to solve this problem
I have tried entering a delay but it stays on for to long and so it doesn't really go along with what I am trying to do. :/
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
import GUI
setscreen ("graphics")
var font : int
font := Font.New ("serif:6")
%Exit
Draw.Line (610, 20, 580, 40, red)
Draw.Line (580, 20, 610, 40, red)
%Font
var Font1, Font2, Font3, Font4 : int
Font1 := Font.New ("sans serif:8:bold")
Font2 := Font.New ("arial:9:italic")
Font3 := Font.New ("mono:8")
Font4 := Font.New ("Arial:24:bold,italic")
%Text
Font.Draw ("Please select the lights you", 65, 290, Font2, 21)
Font.Draw ("wished to be turned on...", 73, 275, Font2, 21)
Font.Draw ("Please HOLD the letter corresponding", 35, 245, Font2, 21)
Font.Draw ("with the desired area", 75, 230, Font2, 21)
Font.Draw ("A = Bedroom", 95, 200, Font1, 21)
Font.Draw ("S = Living Room", 95, 180, Font1, 21)
Font.Draw ("D = Both [ON]", 95, 160, Font1, 21)
Font.Draw ("F = Both [OFF]", 95, 140, Font1, 21)
Font.Draw ("Press 'Escape' to exit program", 53, 100, Font1, 21)
Font.Draw ("Welcome to Song Estate, where you can ", 290, 295, Font3, 21)
Font.Draw ("interact with the lofts. As well, you can ", 290, 280, Font3, 21)
Font.Draw ("select the lights you wish to be turned on.", 290, 265, Font3, 21)
Font.Draw ("If there is any issue with the program,", 290, 100, Font3, 21)
Font.Draw ("please contact 1800-notarealnumber.com", 290, 85, Font3, 21)
Font.Draw ("Bedroom", 290, 220, Font3, 21)
Font.Draw ("Living Room", 490, 140, Font3, 21)
/************************************************
* Bedroom Lights *
************************************************/
View.Set ('onscreenonly')
var chars : array char of boolean
loop
Input.KeyDown (chars )
locate (1, 1)
if chars ('a') then
put "Bedroom Lights " ..
Draw.Fill (310, 200, red, 21)
else
put " " ..
Draw.Fill (310, 200, white, 21)
%Outlining INTERIOR
Draw.Box (280, 240, 590, 130, 21)
Draw.Box (30, 320, 240, 60, yellow)
Draw.Box (280, 310, 590, 260, 21)
Draw.Box (280, 110, 590, 80, 21)
Draw.Line (360, 240, 360, 130, 21)
end if
/************************************************************
* Living Room * *
************************************************************/
if chars ('s') then
put "Living Room Lights " ..
Draw.Fill (410, 200, green, 21)
else
put " " ..
Draw.Fill (400, 200, white, 21)
end if
/************************************************************
* BOTH [ON] *
************************************************************/
if chars ('d') then
put "Both Lights [ON] " ..
for j: 1.. 100
for i : 1.. 100
Draw.Fill (390, 200, green, 21)
end for
Draw.Fill (310, 170, red, 21)
end for
else
end if
if chars ('f') then
put "Both Lights [OFF] " ..
else
put " " ..
end if
end loop
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
MihaiG
![](http://compsci.ca/v3/uploads/user_avatars/2070081168483773c3dead4.png)
|
Posted: Fri May 31, 2013 5:26 pm Post subject: Re: How to get Lights to stop flickering |
|
|
You have a good idea of what's going on! But let me asking you a question
when you turn on a light switch, does it have more than two modes in general? It shouldnt!
Majority light switches as seemed to be part of the scope here is using on or off..
Now what data type might we use to signify two distinct states?
Now we have an idea that we have 2 lighting areas, bedroom and living room, how many of these data types are we going to need?
So now that's setup. So we have to ask ourselves a question, when we turn on a switch and hold it, does the light stay on?
What happens when we let go (in your program lights go off).
So you need to find a way to check..ie
If light a is off and i press a, then turn it on. If light a is off and i press a. turn it off! What happens if i hold a, chances are it might flicker! does this happen i real life? No! So we need to address that, we do that my monitoring if there's been a keypress activated!
This should help you develop your logic. Try and write down your ideas and thought process in words! It makes it easier.
To reduce flickering when animating in turing. Look into View.Update and how that works! The documentation is fairly easy to understand! |
|
|
|
|
![](images/spacer.gif) |
|
|