Addressing an individual pin in a loop
Shmuel
Posts: 14
Toward the begining of my code I have
Now I'm trying to write a subroutine to poll for activity on each switch. Because of the possibility of someone pressing and holding the button, as opposed to pressing and releasing in one cycle, I've decided to write my own routine. (Unless you have something better to recommend.)
Instead of writing a subroutine for each button, I want to have one subroutine poll every button. In pseudo-pseudocode, I'd think it would look like this.
The crux of the problem is using the loop counter in a statement that refers to a specific pin. I'd rather avoid a SELECT statement.
I'm new to Pbasic so it's possible I'm overlooking an instruction.
I'd appreciate your help
Thanks,
Shmuel
BUTTON1 VAR IN1 BUTTON0 VAR IN0 Button1Pressed VAR Bit Button0Pressed VAR Bit
Now I'm trying to write a subroutine to poll for activity on each switch. Because of the possibility of someone pressing and holding the button, as opposed to pressing and releasing in one cycle, I've decided to write my own routine. (Unless you have something better to recommend.)
Instead of writing a subroutine for each button, I want to have one subroutine poll every button. In pseudo-pseudocode, I'd think it would look like this.
FOR count = 0 TO 1 [indent]IF (BUTTON.count = 1) THEN 'I also tried IN.count ... Button|"count"|Pressed = 1 ... ENDIF [/indent] NEXT
The crux of the problem is using the loop counter in a statement that refers to a specific pin. I'd rather avoid a SELECT statement.
I'm new to Pbasic so it's possible I'm overlooking an instruction.
I'd appreciate your help
Thanks,
Shmuel
Comments
Really depends on the larger scope of the program...
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com
I frequently scan multiple inputs with a subroutine.· The code usually looks like this:
Get_Btns:
· btns = %0011
· FOR idx = 1 TO 5
··· btn1 = btn1 & IN0
··· bnt2 = btn2·& IN1
··· PAUSE 5
· NEXT
· RETURN
The variables btn1 and btn2 are aliases for btns.BIT0 and btns.BIT1.· The subroutine scans the buttons and forces them to be pressed for 25 millisceonds before being registered as valid.· If the button is released in the middle of the loop the ANDing of the input will clear that variable.· This technique is discussed in StampWorks.· You can download it from the following link:
http://www.parallax.com/detail.asp?product_id=27220
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Just tried to download that manual, the link will only let you save as a link not the PDF.
I'm planning buy it, but wanted to download it and get a head start!!
Danny
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Never create anything you can't control"
"The amount of intelligence on the planet is fixed... the population is growing"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
You mentioned keeping an eye toward the larger project.
The project is a digital clock/watch. I'm using a DS17887 RTC chip. I've gotten the STAMP to interface with the RTC and can set the time from CON declarations in the file. I'm now trying to up the ante and set the time from buttons as inputs.
For now we'll say there are two buttons. One will scroll through positions: Hrs->Mins->Month->Date. The other will scroll/roll through values in each position.
Let's say that it makes a difference whether the button is pressed or held. For instance to make the values scroll one at a time or quickly.
I was thinking of using BUTTON that I came across before reading your post. Now I'm not sure.
Shmuel
The link to the StampWorks PDF should be working now.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax