A switch is a mechanical mechanism which allows two contacts to be connected together when activated to allow current to flow.
By placing a switch in an appropriate circuit and connecting to a PICAXE input pin the PICAXE can determine if the switch is pressed or not.
Push Switch
Schematic
PCB
Button push detection
The following program looks for button pushes on input pin C.0 and counts those button pushes. When five button pushes have been counted a LED on output pin B.1 will be set. The 'pause 100' acts as a button de-bounce; if it is removed button contact bouncing may cause the LED to be lit prematurely.
- Code Example:
-
init: let b0 = 0 main: if pinC.0 = 1 then add goto main add: pause 100 ; short delay let b0 = b0 + 1 if b0 < 5 then main high B.1 goto main
Copy Code Submit an Example
Create Module
The push switch create module provides an input signal to the PICAXE on the motherboard. The input signal will read high (1) when the push switch is pressed and read low (0) when it is not.
Bill of Materials
Description | Code | Qty | |
---|---|---|---|
Miniature 6mm Tactile Switch | SEN030 | 1 | Buy Now |
Miniature 12mm Tactile Switch | SEN031 | 1 | Buy Now |
10k resistor (pack 100) | RES10K | 1 | Buy Now |
Simulation
Submit Your Own Code!
You must be logged in to submit code examples. Login now.
Share