What's a Microcontroller Digital Input-Pushbuttons

Sorry.
Had to back off the Stepper Motor plan for now.
Was getting in over my head.
Okay. Will work on Button Press.
Had to back off the Stepper Motor plan for now.
Was getting in over my head.
Okay. Will work on Button Press.
Comments
Here's the source code from Stamp Editor BS 1 programs.
' BUTTON.BS1 ' Connect an active-low circuit to pin P0 of the BS1. When you press the ' button, the DEBUG screen will display an asterisk (*). The program, as ' shown below, will print an asterisk at the first button press, then ' delay approximately one second (200 x 5 ms PAUSE) before auto-repeating ' at a rate of approximately 100 ms (5 x 20 ms). Feel free to modify the ' program to see the effects of your changes on the way BUTTON responds. ' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL Btn = 0 SYMBOL btnWrk = B2 Main: ' Try changing the Delay value (255) in BUTTON to see the effect of ' its modes: 0 = no delay; 1-254 = varying delays before auto-repeat; ' 255 = no auto-repeat (only one action per button press) ' ' The BUTTON instruction will cause the program to branch to ' No_Press unless P0 = 0 PAUSE 5 BUTTON Btn, 0, 200, 20, btnWrk, 0, No_Press DEBUG "*" No_Press: GOTO Main
Mike
Have a heart!
Debounce routines are where I was up to with PIC Assembler tutorial.
Nasty. Nasty. Nasty.
Mike
What does this program do?
Is it only checking once for button press?
I am going to look in What's a Microntroller.
Just for a little more information. Not a lot!
That was a bad idea.
I am going to just stick with this example.
How do I wire up button as 'active low' button?
It's a parallax breadboard button.
Main: PAUSE 5 btnWork = btnWork + 5 * Btn IF btnWork < 25 THEN Main
Important note for this to work: Btn must be an alias for a PINx variable. This allows the line after the PAUSE to accumulate the debounced timing if the button is pressed, or reset it to zero if the button input is low. Remember: In the BS1, there is no operator precedence; expressions are evaluated left to right. In this case, five is added to timer and then multipled by the state of the button pin. If the button is pressed, Btn evaluates as 1 and the timer accumulates; if the button is released then Btn evaluates as 0 and the timer variable is cleared.I was at LA Comic Con yesterday and saw lots of Cosplays with boring LEDs. Even the BS1 can spice things up with a simple bit of code. Here's a real-world program that I use as a demo for the Prop-1 controller with a trainer board (which has 6 LEDs and a button).
Main: PAUSE 5 ' debounce delay timer = timer + 5 * Trigger ' update trigger timer IF timer < 100 THEN Main ' button debounced? Zig_LEDs: FOR ledPin = 0 TO 4 ' forward through LEDs HIGH ledPin ' LED on PAUSE 75 ' hold LOW ledPin ' LED off IF Trigger = IsOff THEN Main ' button released? NEXT Zag_LEDs: FOR ledPin = 5 TO 1 STEP -1 ' go backward HIGH ledPin PAUSE 75 LOW ledPin IF Trigger = IsOff THEN Main NEXT GOTO Main
The complete listing is attached so you don't have to re-type it. One of the "advanced" things you'll notice is that the loops use different pins -- this prevents the bounce delay on the ends of the strip of LEDs.One button contact to ground, the other to the I/O pin, and a pullup resistor (~10K) to Vcc.
Kwinn
Thank you.
Found Prop example. Got out of it because there was too much going on in it.
Your explanation will work fine.
Keeping it simple.
Jon
Thanks!
Let me get this going 'as-is'.
Then look at your ideas.
EFX-TEK (I co-created) has sold a couple thousand Prop-1 (industrialized BS1) controllers across the world from everyone to home Halloween decorators to major amusement parks that you've probably visited. In fact, there is a Christmas tree on display at a very famous SoCal amusement park that has 80 Prop-1 controllers creating a faux candle effects. My customers aren't looking for ideas, they're looking for solutions that work in their applications.
You can continue to post blurbs from the (20 year old) help file, but those are not proving that you're learning anything, nor are you providing any new information for other forum members.
Jon
Okay.
Will finish this experiment tomorrow.
Changing over to Basic Stamp 2 What's a Microcontroller button experiment.
Need step by step through this.
Going to go look for a Homework board.
Here's my standard BS2 template for the EFX-TEK Prop-2 controller -- note that it does debouncing in a loop and allows the user to specify active-high or active-low trigger input.
' ========================================================================= ' ' File...... ' Purpose... ' Author.... ' E-mail.... ' Started... ' Updated... ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- Sio PIN 15 ' no ULN, SETUP = UP Trigger PIN 14 ' SETUP = DN ' -----[ Constants ]------------------------------------------------------- IsOn CON 1 ' for active-high in/out IsOff CON 0 TrOn CON 1 TrOff CON 0 Yes CON 1 No CON 0 T1200 CON 813 ' serial constants T2400 CON 396 T4800 CON 188 T9600 CON 84 T19K2 CON 32 T38K4 CON 6 SevenBit CON $2000 Inverted CON $4000 Open CON $8000 Baud CON Open | T38K4 ' for EFX-TEK accessories ' -----[ Variables ]------------------------------------------------------- timer VAR Word ' -----[ Initialization ]-------------------------------------------------- Reset: OUTH = %00000000 : OUTL = %00000000 ' clear all DIRH = %00000000 : DIRL = %00000000 ' set outputs ' -----[ Program Code ]---------------------------------------------------- Main: timer = 0 DO WHILE (timer < 100) ' debounce = 100ms PAUSE 5 IF (trigger = TrOff) THEN GOTO Main ELSE timer = timer + 5 ENDIF LOOP ' program code here GOTO Reset ' -----[ Subroutines ]----------------------------------------------------- ' ------------------------------------------------------------------------- ' -----[ User Data ]-------------------------------------------------------
Thank you Jon
Still working my way up to that point.
Right now.
Will the Parallax Serial to USB adapter work with the Basic Stamp Homework boards?
Parallax pushes it for the Stamp 1 Project board but not the Homework boards.
Wondered if there was a snag there.
EFX-TEK (JonnyMac's company) does have a USB to BS1 adapter that takes the place of a USB to Serial Adapter plus a Serial to BS1 Adapter.
Here's another tidbit.
Light on Homework board is a 'programming activity' light.
Light on BOE is 'board powered' light.
Have time to notice these things now. At least for a little while.
Have two Serial Homework boards.
Okay. Parallax Serial to USB works with them.
Light on board did light up while program downloaded and then went off.
Will continue this later.
And here's a generic USB-to-TTL adapter connected with jumper wires.
Yes, both work. In fact, the USB2SER thing is what caused me to create the USB-BS1 Serial Adapter for EFX-TEK.
Thanks Jon
Ran a 'Print to Terminal' program and it worked.
USB to Serial only is for communication. It does not provide USB power.
So. Terminal program with Identify reported COM port 4 but no stamp.
Had to put battery in Homework board.
Yes. That looks like a good USB to TTL board.
Fixed the title.
Will build circuit tomorrow.
'Test Pushbutton'.
Get used to that 4 lead pushbutton.
Ken
Let me get back to you about that.
We're on a roll here.
Will build 'test button' circuit here shortly.
Actually caught on to the part about 'pull down' and 'pull up' resistor.
It's the 10K one on the 'opposite leg' of main circuit.
Funny way to put it but that's the gist of it.
(Fixed typo -- thanks, Dave)
A pull-down is used when the input signal is active-high.
A pull-up is used when the input signal is active-low.
In breadboard experiments we tend to use active-high inputs because it's easier to think of having a "high" signal as on.
Why use an input with a pull-up? Well, in the industrial world there are a lot of sensors and devices with "open-collector" outputs. This means that the output looks disconnected until active; when active the sensor provides a connection to ground which pulls the input down. You just have to remember that when reading the pin "1" is off, and "0" is on.
Another area where pull-ups are used is the I2C bus between the processor and EEPROM. The pull-up creates the "1" state on the bus and either end can connect to ground to provide the "0" state.
Did you mean pull-up on both statements?
Will put some of the lesson circuits together today and post pic's.
One problem with these older boards is they run the serial port out the top.
That was for serial and parallel ports coming out the back of desktops.
Now with tower's under the desktop and laptops you want the USB connector on the bottom of the board.
I have to run the cable around to the top to keep board 'right side up'.
I have to put a block of steel on the cable to keep the heavy cable from dragging little board off the table.
Waah!
Found a pushbutton and mounted it on breadboard.
Here's pushbutton test circuit.
It works.
Next is 'Turn LED off with pushbutton'.
It does not look like 'pull-down' or 'pull-up' circuit.
Looks like a shunt one.
-- https://www.parallax.com/product/28030