-
Notifications
You must be signed in to change notification settings - Fork 71
Project 3: 2 bit counter
This project will combine the circuits from both Project 1: Morse Code and Project 2: Simple Switch into a larger circuit.
If you have not reviewed those projects, please do so.
The basic idea of this project is to build a circuit that "counters" in binary. There will be two LEDs and a switch, pressing the switch increments the count by 1.
For this project you will need:
- 2 LEDs
- 2 1K OHM resistors
- 1 momentary switch
- 1 10K OHM resistor
Connect a 1K resistor and an LED to GPIO #17, following the same circuit we used for project 1. Next, connect a 1K resistor and an LED to GPIO #27.
Finally connect a 10K resistor and momentary switch to GPIO #22 following the circuit we used for project 2.
The software for the circuit is rather simple, increment a counter and check it's modulo:
PiPiper.watch :pin => 22, :trigger => :rising do |pin|
sum = sum + 1
display = sum % 4
puts sum
pin17.update_value(display == 2 || display == 3)
pin27.update_value(display == 1 || display == 3)
end
The full sample app can be found here.