PDA

View Full Version : Counting down while gradually flashing and waiting for a button push.



IAmTheAnswer
- 11th May 2010, 19:17
I started using DT's Interrupt Routine.

I have

- a switch
- a led

I now want to count from a given number z (between 7200 seconds and 180 seconds) to zero. While this happens, the led should flash. Say z is at it's beginning then the led's on and off-time equals 800ms. Then this should gradually decrease to 50ms when it's 1 or zero.
At all this time the code should watch for the switch to be pressed. If it is, the counting and flashing should stop. When the switch is pressed again, it should continue counting and flashing.

I tried so much. I tried using a while...wend loop, put the counting in and started the interrupt with the flashing led before. That did not work - it never took z seconds. Then I put the flashing light in the main routine and the counting in the interrupt routine. Still issues.

I guess this has been done before. How would you approach this?

I'd be happy if you shared some code.

sayzer
- 12th May 2010, 07:14
Post your code(s) that you worked on.
Then lets us see what you have done. Lets modify yours, so your work is not wasted !

____________________________

IAmTheAnswer
- 12th May 2010, 08:19
This code waits for one of 3 buttons to be pushed. Depending on which button is being pushed zaehler (equals z) changes.

"If Timerzaehler = 781 AND Zeit = 400 Then" means that 781 times interrupt timer0 should be close to 400ms being elapsed.

Having done all the counting, a song is being played which should be stopped by pressing a button.



Starten:
'PICProg-Einstellungen
DEFINE OSC 4
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines
'Initialisierung
INTCON = 0
CMCON = 7
TRISB = %01111000
TRISA = %11111111
'Variablen
Position VAR WORD
TimerZaehler VAR WORD
Lied_Zuende VAR BIT
Zaehler VAR WORD
Zeit VAR WORD
Prozent VAR WORD
Zaehlervariable VAR Word
LiedPausenzeit Var Word
WH Var Word
AePosition Var Word
LED_Lied VAR BIT
'Hardwarezuweisungen
Aufnahme_Taster VAR PORTA.2
Stop_Taster VAR PORTA.3
Abspielen_Taster VAR PORTA.4
LED_Aufnahme VAR PORTB.0
LED_Stop VAR PORTB.1
LED_Start VAR PORTB.2
Lautsprecher VAR PORTB.7
'Konstanten
Ja CON 1
Nein CON 0
Gedrueckt CON 0
Frei CON 1
Aus CON 0
An CON 1
LED CON 0
Lied CON 1

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR0_INT, _LEDAnAus, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

'T1CON = $1 ; Prescaler = 4, TMR0ON
OPTION_REG = $80




Einschalten:
while Ja = Ja
Beginn:
'Warten auf Start, Aufnahme oder Stop
Position = 1
Lied_Zuende = Nein
LED_Lied = LED

if Abspielen_Taster = Gedrueckt then
Pause 500
Zaehler = 1260
Gosub Gleichbleibend
LED_Aufnahme = Aus
GOSUB RedRedWine
else
if Stop_Taster = Gedrueckt then
Pause 500
Zaehler = 180
Gosub Gleichbleibend
LED_Aufnahme = Aus
GOSUB RedRedWine
else
if Aufnahme_Taster = Gedrueckt then
Pause 500
Zaehler = 7200
Gosub Gleichbleibend
LED_Aufnahme = Aus
GOSUB RedRedWine
EndIf
EndIf
EndIf

WenD
END

Inhalt:
Toggle LED_Aufnahme
Timerzaehler = 0
WH = WH - 1
Return

LEDAnAus:
TimerZaehler = TimerZaehler + 1
If Timerzaehler = 781 AND Zeit = 400 Then
Gosub Inhalt
ELSE
If Timerzaehler = 391 AND Zeit = 200 Then
Gosub Inhalt
Else
If Timerzaehler = 195 AND Zeit = 100 Then
Gosub Inhalt
Else
If Timerzaehler = 98 AND Zeit = 50 Then
Gosub Inhalt
EndIf
EndIf
EndIf
EndIf
@ INT_RETURN

Abspielen:
Zaehler = Zaehler * 1000

WH = DIV32 Zeit
WH = WH / 4
TimerZaehler = 0
@ INT_ENABLE TMR0_INT
WHILE WH >= 1
if Abspielen_Taster = Gedrueckt OR Aufnahme_Taster = Gedrueckt OR Stop_Taster = Gedrueckt then
@ INT_DISABLE TMR0_INT
Pause 500
WHILE Abspielen_Taster = Frei AND Aufnahme_Taster = Frei AND Stop_Taster = Frei
WEND
Pause 500
@ INT_ENABLE TMR0_INT
EndIf
Wend
@ INT_DISABLE TMR0_INT
Zaehler = Zaehler / 1000
Return

Liedpause:
Return

RedRedWine:
LED_Lied = Lied
'While Lied_Zuende = Nein And Abspielen_Taster = Frei And Aufnahme_Taster = Frei And Stop_Taster = Frei
While Abspielen_Taster = Frei And Aufnahme_Taster = Frei And Stop_Taster = Frei
Sound Lautsprecher,[0,0,104,44,0,8,109,44,0,8,110,94,0,13,106,94,0,120 ,112,39,0,0,114,39,0,0,0,26,0,0,114,46,0,0,110,39, 0,0,106,114]
Sound Lautsprecher,[0,127,112,33,0,0,114,39,0,0,0,26,0,0,114,39,0,0,11 0,39,0,0,110,71,0,170,106,39,0,0,104,39,0,0,101,26 ,0,0,104,39]
Sound Lautsprecher,[0,0,106,12,0,0,104,147]
Wend
High LED_Aufnahme
Pause 1000
PORTB.7 = 0 'LS aus
Low LED_Aufnahme
RETURN

Gleichbleibend:
Zeit = 400
Sound Lautsprecher,[90,74]
GOSUB Abspielen
Zeit = 200
Sound Lautsprecher,[97,74]
GOSUB Abspielen
Zeit = 100
Sound Lautsprecher,[103,74]
GOSUB Abspielen
Zeit = 50
Sound Lautsprecher,[109,74]
GOSUB Abspielen
Return

IAmTheAnswer
- 12th May 2010, 14:37
Advice could be helpful.

HenrikOlsson
- 12th May 2010, 16:50
Look, this is a list of PBP users, just like yourself. No one gets paid or otherwise compensated for the time spent helping out others - it's a give and take kind of thing. You just can't expect people to, within a 6 hour timeframe, digest a piece of code 166 lines long, with comments, labels and variable names in a language the majority don't understand as well as you do then figure out what's wrong with it and post it.

Personally I still haven't understood what the actual problem is - or even if there IS a problem.

So, come on, play nice, ask nice and give the awsome guys and girl(s) a chance - some may not even be awake during the whole 6 hours you waited.

/Henrik.

Darrel Taylor
- 13th May 2010, 00:16
I started using DT's Interrupt Routine.

I have

- a switch
- a led

I now want to count from a given number z (between 7200 seconds and 180 seconds) to zero.
I DO NOT do count down timers with actions at 0.

No one can stop you if you do.
But I would prefer you not use my software to do it.
And certainly, don't publish it.

Sorry, it's a personal thing.

Best regards,

IAmTheAnswer
- 13th May 2010, 08:37
HenrikOlsson:

Look, there are thousands of forums on the internet with volunteers on it. Average time to get a quality answer is one hour. Speaking of giving and taking, we have not seen you giving anything but useless lecture which tells us more about your insecurities than you think.

I know that you still don't understand what the actual problem is, because you would not be a giver even if you understood it.

So, come on, play nice, ask nice and give the awesome guys and girl(s) a chance to actually give - some may not even be awake during the whole 6 hours and the first thing they see is you claiming "I am insecure please give me attention.".

Darrel Taylor, dear. Count down from 10 to 0 and rethink your writing

mackrackit
- 13th May 2010, 08:49
Look, there are thousands of forums on the internet with volunteers on it.
Then please go to one of the other forums if you are not receiving the answer you seek here.

You should have the knowledge you seek with in an hour.

IAmTheAnswer
- 13th May 2010, 09:27
mackrackit, recommend a forum or a newsgroup or similar where pbp-issues are being discussed and a reaction is to be expected within an hour and I 'll be gone.

What is very interesting, you are fast to complain but slow to respond. It took you 12 minutes (!) to complain and lecture but you were not able to even answer a part of the question in this time. Everyone can grouch, giving a useful answer is what shows a decently trained brain.

malc-c
- 13th May 2010, 22:12
Speaking of giving and taking, we have not seen you giving anything but useless lecture

Errr... use the search function and find out just how much Henrik has given to this forum.. here's one example http://www.picbasic.co.uk/forum/showthread.php?t=5874

I must admit you have a talent for upsetting three of the most respected member on this forum.:rolleyes:

IAmTheAnswer
- 14th May 2010, 07:42
Use the page search function and find out just how little Henrik has given to this thread.. nothing to be precise.

I must admit you have a talent for talking useless rubbish, aswell.

Acetronics2
- 14th May 2010, 10:11
Use the page search function and find out just how little Henrik has given to this thread.. nothing to be precise.

I must admit you have a talent for talking useless rubbish, aswell.

Hi, THE Answer

the question was " can you share some code " ...

THE Answer is " we do not have such code " ... :o I think you can find it on Paintball sites ...

VERY simple to understand.

Add to that German is a language few people here can understand ... sorry, but it is.

Alain