473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Button pause

93 64KB
Hey something else today!

Any comments you dont understand is in norwegian... so just forget those

I MINOR problem with my basic stamp 2.5 code. I'm trying to get a 8-bit counter so stop counting in its tracks by just pushing the buttonPin quickly once. if you press it again the counter should start to count normally from were it stopped. Now I have pretty much tried to rewrite and debug the code for over a week. It should work for me but it doesn't. The problem is with reading if buttonPin has been pressed.

PLEASE HELP ME!!!!!!

Expand|Select|Wrap|Line Numbers
  1.  
  2. ' {$STAMP BS2}
  3. ' {$PBASIC 2.5}
  4.  
  5. ' ---[ Programbeskrivelse ]--------------------------------
  6. '
  7. ' Viser en 8-bits binærteller på LED koplet til P0 - P7.
  8. ' Dette programmet fungerer som en vanlig BS-2 teller men med et par ekstra funksjoner.
  9. ' Trykker du på Knapp 0 kan du pause og starte kretsen.
  10. ' Vrir du på potentiometeret kan du endre hastigheten telleren teller.
  11.  
  12. ' ---[ I/O Definisjoner ]----------------------------------
  13.  
  14. Pot              PIN 14                                                  ' definerer pinne 14 som Pot
  15. buttonPin        PIN 15                                                  ' definerer pinne 15 som buttonPin
  16.  
  17. ' ---[ Konstanter ]----------------------------------------
  18.  
  19. MinCount  CON  0                                                         ' tellers startverdi = 0
  20. MaxCount  CON  255                                                       ' tellers sluttverdi = 255
  21.  
  22. ' ---[ Variabler ]-----------------------------------------
  23.  
  24. cntr          VAR      Byte                                              ' variabel for 8-bits teller
  25. PotVal        VAR      Word                                              ' definerer variabelet PotVal som Word
  26. currentState  VAR      Bit                                               ' definerer et variabel som heter currentState
  27. LEDs          VAR      OUTL                                              ' LED-er på P0 - P7
  28. LEDsDirs      VAR      DIRL                                              ' DIRS kontroll for LEDs
  29. whileBreak    VAR      Bit                                               ' definerer et variabel som heter whileBreak
  30.  
  31. ' ---[ Initialisering ]------------------------------------
  32.  
  33. LEDsDirs = %11111111                                                     ' DIRS kontroll til LEDene
  34. LEDs = %11111111                                                         ' gjør LEDene til utganger
  35. currentState = 1                                                         ' setter currentState = 0 som er standar verdi
  36. whileBreak = 0                                                           ' setter whileBreak = 0 som er standar verdi
  37.  
  38. ' ---[ Programkode ]---------------------------------------
  39.  
  40. Main:                                                                    ' starter en hoved funksjon som heter: main
  41.   FOR cntr = LEDs TO MaxCount                                            ' sløyfe gjennom alle verdiene
  42.     GOSUB pauseButton                                                    ' Starter en "sub routine" some heter: pauseButton
  43.     GOSUB Read_Pot                                                       ' Starter en "sub routine" some heter: Read_Pot
  44.     DEBUG DEC ? PotVal                                                   ' Gjør om verdiene den får fra PotVal om til desimaltall som programmet kan bruke
  45.     LEDs = cntr                                                          ' send count til LEDs
  46.     PAUSE PotVal                                                         ' pauser programmet i PotVal mengde
  47.   NEXT
  48.   IF MaxCount THEN OUTL=0 ELSE GOTO Main                                 ' hvis cntr = MaxCount, avsluttes loopen og programmet går videre
  49.   GOTO Main                                                              ' går til main
  50.  
  51. Read_Pot:                                                                ' starter en "Sub Routine" som heter: Read_Pot
  52.   HIGH Pot                                                               ' Sender en puls til kondensatoren slik at den lades opp
  53.   PAUSE 1                                                                ' Pauser i 1 ms for å gi kondensatorenen til å lade seg litt ut
  54.   RCTIME Pot, 1, PotVal                                                  ' Leser oppladnings/utladningds hastigheten på kondensatoren
  55. RETURN                                                                   ' hopper opp til neste linje i main funksjonen
  56.  
  57. pauseButton:                                                             ' starter en ny under funksjon som heter pauseButton
  58.     IF buttonPin = 0 & currentState = 1 THEN                             ' hvis buttonPin = 0 og currentState = 0, fortsett
  59.       DEBUG DEC ? currentState, CR                                       ' konverterer og printer ut et desimaltall av currentState verdien
  60.       currentState = 0                                                   ' redefinerer currentState = 0 slik at du kan pause kretsen
  61.       GOSUB pauseSeq                                                     ' går til en "sub routine" som heter pauseSeq
  62.     ENDIF                                                                ' ender if-statement
  63. RETURN                                                                   ' returnerer til der den var i main
  64.  
  65. pauseSeq:                                                                ' starter en "sub routine" som heter pauseSeq
  66.   DO WHILE whileBreak < 1                                                ' repeter mens whileBreak < 1
  67.     PAUSE 1                                                              ' pauser programmet i 1 ms
  68.     IF buttonPin = %0 & currentState = 0 THEN                            ' hvis buttonPin = 0 og currentState = 0, fortsett
  69.       whileBreak = 5                                                     ' redefinerer whileBreak = 1
  70.     ENDIF                                                                ' ender if-statement
  71.     whileBreak = 0                                                       ' redefinerer whileBreak som 0 for å starter telling senere
  72.   LOOP                                                                   ' looper tilbake til do
  73. RETURN                                                                   ' returnerer til pauseButton
  74. ' ----------------- Extra tileggs oppgaven er levert i et eget program ------
  75.  
  76.  
Dec 1 '14 #1
0 1528

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Brian.Steele | last post by:
Greetings everyone. See http://www.spiceisle.com/cgi-bin/slideshow/slideshow.cgi?dir=brian/personal/2005/uk_trip/images&type=jpg The "Pause" button works in IE, but not in Firefox. Any ideas...
8
by: Wim | last post by:
My GUI application starts a process (a console program) when the user hits Play. I would like to add an option to pause that process. The code I've added to detect if the user hit pause/unpause...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
3
by: JimJam | last post by:
Hello Peeps I have created a program in VB.NET 2003 that counts down from 7.5 hours to zero from 08:00. I have a button that starts a new countdown from 1 hour to zero whilst the first one is...
6
by: Peted | last post by:
Hi wondering what is the best way to do this Need a user to click a button, that sends 3 or 4 string based commands via a TCP/ip socket link I can connect to the ip device no problems, am...
3
by: garfunkel214 | last post by:
I have images and text rotating every 7000 ms using a setInterval. i am trying to implement a pause button that will stop the rotation when clicked. When clicked once more, I would like the rotation...
2
by: thomas.lidebrandt | last post by:
Hello I'm using wxPython to consruct a GUI and want to change a button label and event handler to change after the button have been pressed. The only thing I can think of is a global variable...
3
by: nma | last post by:
Hi This code goes well with play, stop and fullscreen button, the only thing is the pause button is not there. How to make pause button? I try to make pause button but when it streams video, when...
3
by: shimajavar | last post by:
Hi all I have the following code: a line is growing up by clicking on "up" button, it has another button"start" which I want it to stop the process of growing the line...How can I make a button to...
2
by: keeplearning | last post by:
Hi Friends ! Please view this ANIMATION . I want to control this animation with a play and pause button . when clicked on play button , the animation should start playing . and when clicked...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.