keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

tutorial_6_active_high.md 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. Tutorial 6 - Active high
  2. =========================
  3. This tutorial pulls together several concepts needed to understand active state in the context of a keyboard.
  4. Skip to the end of this tutorial if you just want to copy an active-high keyboard.
  5. Pull-up resistors
  6. -----------------
  7. There are many sources that explain "pull-up resistors", so I won't repeat it here.
  8. Here is a [good tutorial on Pull-up Resistors](https://learn.sparkfun.com/tutorials/pull-up-resistors/what-is-a-pull-up-resistor).
  9. Active low
  10. ----------
  11. All the keyboards up to this point in the tutorial series have used active low with internal pull-up resistors.
  12. "Active low" means that if a switch is pressed (active state), the read pin is low.
  13. When the switch is released (inactive state), the pull-up resistor pulls the read pin high.
  14. The following table traces the strobe current from left to right (0 is ground, 1 is power).
  15. If the switch is closed, the strobe current passes through the switch and pulls the read pin low.
  16. If the switch is open, the pull-up resistor pulls the read pin high.
  17. <br>
  18. |Strobe pin on | Diode orientation | Switch position | Pull resistor | Read pin state |
  19. |:------------:|:------------------:|:---------------:|:-------------:|:---------------:|
  20. | 0 | cathode -:<- anode | close | 1 pull-up | 0 active low |
  21. | 0 | cathode -:<- anode | open | 1 pull-up | 1 inactive high |
  22. <br>
  23. Arduino boards have internal pull-up resistors, which saves on parts and labor compared to manually adding external pull resistors.
  24. To make a keyboard active low:
  25. * Orient diodes with cathode (banded end) towards the write pins (row)
  26. * Define strobe on and strobe off in the sketch like this:
  27. ```
  28. const bool Scanner_uC::STROBE_ON = LOW;
  29. const bool Scanner_uC::STROBE_OFF = HIGH;
  30. ```
  31. Active high
  32. -----------
  33. "Active high" means that if a switch is pressed (active), the read pin is high.
  34. When the switch is released (inactive), the pull-down resistor pulls the read pin low.
  35. The following table traces the strobe current from left to right (0 is ground, 1 is power).
  36. If the switch is closed, the strobe current passes through the switch and pulls the read pin high.
  37. If the switch is open, the pull-down resistor pulls the read pin low.
  38. <br>
  39. |Strobe pin on | Diode orientation | Switch position | Pull resistor | Read pin state |
  40. |:------------:|:------------------:|:---------------:|:-------------:|:---------------:|
  41. | 1 | anode ->:- cathode | close | 0 pull-down | 1 active high |
  42. | 1 | anode ->:- cathode | open | 0 pull-down | 0 inactive low |
  43. <br>
  44. Arduino boards do not have internal pull-down resistors.
  45. If you want to use active low, you will have to add external pull-down resistors to the read pins.
  46. To make a keyboard active high:
  47. * Add an external 10k pull-down resistor to each read pin
  48. * Orient diodes with cathode (banded end) towards the read pins
  49. * Define strobe on and off in the sketch like this:
  50. ```
  51. const bool Scanner_uC::STROBE_ON = HIGH;
  52. const bool Scanner_uC::STROBE_OFF = LOW;
  53. ```
  54. Making a breadboard keyboard active-high
  55. ----------------------------------------
  56. This tutorial converts the basic breadboard keyboard from tutorial 1 to active high.
  57. By comparing the above tables, one can see what changes need to be made:
  58. * add external pull-down resistors to the read pins
  59. * flip the diodes so that the cathode (banded end) are towards the read pins
  60. * swap the STROBE_ON and STROBE_OFF values
  61. The red bus is grounded.
  62. The pull-down resistors plug into the red bus and column read pins.
  63. The [keybrd_6_active_highsketch.ino](keybrd_6_active_high/keybrd_6_active_high.ino) is the tutorial 1 sketch with STROBE_ON and STROBE_OFF values swapped.
  64. ![pull_down_resistors.JPG](keybrd_6_active_high/pull_down_resistors.JPG "Active-high diodes and pull-down resistors")
  65. <br>
  66. <a rel="license" href="https://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">keybrd tutorial</span> by <a xmlns:cc="https://creativecommons.org/ns" href="https://github.com/wolfv6/keybrd" property="cc:attributionName" rel="cc:attributionURL">Wolfram Volpi</a> is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.<br />Permissions beyond the scope of this license may be available at <a xmlns:cc="https://creativecommons.org/ns" href="https://github.com/wolfv6/keybrd/issues/new" rel="cc:morePermissions">https://github.com/wolfv6/keybrd/issues/new</a>.