how to make a out_time?
daniel ding
Posts: 52
hi everyone
in my program I want to make a out-time of operation.
For one if I press the TAB key, the operation will get a out_time and when I press it again it continues.
I tried (repeat wiatcnt(), pub abort and quit commands but useless)
can u give me some advises.
thanks
Daniel
in my program I want to make a out-time of operation.
For one if I press the TAB key, the operation will get a out_time and when I press it again it continues.
I tried (repeat wiatcnt(), pub abort and quit commands but useless)
can u give me some advises.
thanks
Daniel
Comments
In the main loop you would simply check this variable. If it is FALSE you would do what the loop has to do, if it is TRUE you would wait in an empty
repeat while outTime
loop for the flag set to FALSE again.
The keyboard part needs to run in a separate COG and simply toggles the variable outTime each time the TAB is pressed.
If you have more than one COG running a program that should be paused, they all have to check this variable.
Of course this will only pause the execution when you reach that part of the main loop. Depending on the program this might be a long time to go. In this case you can add several of these checks and wait-loops at strategic places.
I don't have a LCD connected to a Propeller right now so I used a terminal object.
This program will start the method "DoStuff". "DoStuff" will stop when the tab key is pressed. A second tab press will restart "DoStuff".
Good luck.
Thanks for ur reply
U are so nice guy!
Are u sure ur program ok?
everytime I press TAB it stop and it restart when I press it again。
But I want it continues!
for example when x=4 I press TAB it stops, when I press TAB again it will display x=5
It does not compile?
It does not react on keyboard-input?
It does not show anything at all in the Propeller Serial Terminal?
It is showing garbage?
We are not clairvoyants that can see by magic what exactly your problem is. You should put a little bit more efford in your questions if you want to have good answers.
In a word it didn't stop when I press TAB and continue when I press tab again.
Thanks Magl02
For this demo code it would be easy ... simply move x into the VAR section and it can continue where it stopped.
For a more complex program maybe with different COGs running, I'd like to refere to my first post ... set a global flag and check this where ever your program should be stopable. Translated to this demo:
(I did not test this code as I am at work, but hopefully it compiles and at least gives you an idea)
I think MagIO2 already answered your question.
The "DoStuff" method I included sets x to zero when the method is called. Local variables need to be initialized. I was hoping the difference between a local and global variable was already known to you.
By the way, MagIO2 is a much better programmer than I am. I also think he's a nice person. I plan to read his example to see what I can learn.
I just looked at it. Yes, that is a good way to do it. It does require "DoStuff" to run in a seperate cog. If I have enough cogs, I do the same sort of thing in my projects.
Having one cog check a flag set by another cog is an important part of learning to use the Propeller. I like MagIO2's example better than the example I wrote.
for example if I press the keyboad 2,a3 will =(50-48)*0.1 50:is the ascii of 2.
and the LCD should display a 0.2, but it display a wrong number .
BUT when I change the "lcd.print(fs.floattostring(a3))" to "lcd.print(floattostring(0.2))" the LCD displays 0.2.
Can u tell me what's wrong with my codes?
Thanks
Daniel
I'm not familiar with the float object so far, so I can't tell which functions are available to convert from one representation to float.
If there is a LONG to float conversion available, you can call that with
keyinput10-"2"
and then use the result in the fmul.
If there is a STRING to float conversion available, you can put the "2" into a conversion string-buffer, call the STRING to float and use the result in fmul. Or even easier then, you prepare the string buffer in a special way and get the fmul for free.
... ah ... I see ... you use floatstring ... which makes me believe that you can convert from string to float. Here is the way you could go: This code replaces the x in the DAT-string with the number entered. In a good program you would also make sure that keyinput10 really contains a number.
In your LCD.str you can directly use @convBuffer as well, which saves you the conversion back to string again. If you want to see that the conversion to float worked correctly you can keep that code as it is.
Then the first approach is the way to go:
PS: Another bug you had is that you did a double conversion. First you did this:
a3:=fs.floattostring(fm.fmul(fm.fsub(keyinput10,48),0.1))
and then
lcd.print(fs.floattostring(a3))
But a3 does not contain a float here. In strictly typed programming languages the compiler would check these things. But in the Propeller Tool you have to take care of what you do with your variables by yourself. So, for debugging you always should have the following questions in mind:
What type do the functions expect as parameters (long, string pointer, float ...)
What do I actually pass (e.g. in fm.fsub(2.0, 0.1) )
Or what do the variables contain that are used in function calls (e.g. fs.floattostring(a3) )
Good idea is to use variable-names which remind you what type of data they contain.
Thanks
I got it!
Thanks a lot to your reply.Daniel