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_5_LEDs.md 4.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. Tutorial 5 - indicator LEDs
  2. ===========================
  3. Keyboards often have LEDs to indicate CapsLock, NumLock, and other states.
  4. It's one of the first things we look at when a keyboard produces unexpected results.
  5. Adding LEDs to the basic breadboard keyboard
  6. --------------------------------------------
  7. The breadboard keyboard modifies the basic breadboard keyboard described in [tutorial_1_breadboard_keyboard.md](tutorial_1_breadboard_keyboard.md)
  8. Add components to the breadboard as shown in the picture.
  9. The three clear plastic cylinders are LEDs.
  10. LED anodes (the longer lead) are powered by 4.7k Ohm current limiting resistors connected to pins 16, 17, and 21.
  11. LED cathodes (the shorter lead) are grounded by a common terminal strip.
  12. !["LEDs"](keybrd_5_LEDs/LEDs_back.JPG "LEDs")
  13. keybrd sketch for driving LEDs
  14. ------------------------------
  15. [keybrd_5_LEDs.ino](keybrd_5_LEDs/keybrd_5_LEDs.ino) is a simple sketch with three LEDs.
  16. The sketch will run on the above breadboard keyboard.
  17. As usual, the sketch annotations explain the code.
  18. LED brightness
  19. --------------
  20. An LED's current limiting resistor value effects the brightness of the LED.
  21. Lets see how much visual difference resistance makes.
  22. Replace an LED's 4.7k Ohm resistor with a 270 Ohm resistor.
  23. It doesn't matter which end of the LED the resistor is on, the important thing is that the resistor and LED are in series.
  24. Less resistance makes the LED brighter.
  25. Too little resistance will burn out the LED.
  26. Connecting an LED directly to power will destroy the LED in a bright flash (do not look directly at the LED if you try this).
  27. 2-mA LEDs are bright enough for keyboard indicator lights.
  28. Or you can use more resistance on a 20-mA LED to make it dimmer.
  29. LED current limiting resistor values
  30. ------------------------------------
  31. Never connect an LED directly from ground to power. Doing so would destroy the LED.
  32. This formula calculates the minimum resistance for maximum LED brightness:
  33. ```
  34. output-pin Supply Voltage Vs
  35. LED Forward Voltage Vf
  36. Forward Current If
  37. minimum current limiting restiance R = (Vs - Vf) / If
  38. ```
  39. For Forward Current, use the smaller of:
  40. * Current capacity of output pin
  41. * Continuous Forward Current of LED
  42. Teensy LC output-pin capacities are:
  43. * four 20 mA pins (5, 16, 17, 21)
  44. * nineteen 5 mA pins
  45. * Teensy LC on-board LED is on pin 13.
  46. It has a current-limiting resistor on the board, and does not provide enough power for another LED.
  47. For Teensy LC 20 mA pin and the TT Electronics OVLLx8C7 LED:
  48. ```
  49. output-pin Supply Voltage Vs = 3.3 volts
  50. LED Forward Voltage Vf = 2.2 volts
  51. max pin Current If = 20 mA
  52. max LED Current If = 20 mA
  53. minimum current limiting restiance R = (Vs - Vf) / If = 55 Ohms
  54. ```
  55. It is safe to use more resistance.
  56. Calculating the resistance for the Teensy LC 5 mA pin is left as an exercise.
  57. Through-the-hole resistors have color coded bands that indicate resistance value.
  58. https://en.wikipedia.org/wiki/Electronic_color_code#Resistor_color-coding
  59. Exercises
  60. ---------
  61. 1) In this exercise you will calculate the minimum current limiting resistance needed for your output pin and LED.
  62. For your microcontroller, find:
  63. * Supply Voltage coming out of the output pins
  64. * Current (mA) capacity of the output pins
  65. From your LED's datasheet, find:
  66. * Forward Voltage
  67. * Continuous Forward Current (mA)
  68. Calculate the minimum resistance needed for your LED and Supply Voltage.
  69. There are several "LED current limiting resistor calculators" on line.
  70. <br>
  71. <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>.