|
| 1 | +--- |
| 2 | +title: Using the EV3 LEDs |
| 3 | +group: hardware-standard |
| 4 | +--- |
| 5 | + |
| 6 | +* Table of Contents |
| 7 | +{:toc} |
| 8 | + |
| 9 | + |
| 10 | +### Basics |
| 11 | + |
| 12 | +When the EV3 is booting, the LEDs flash amber (orange). When it is finished |
| 13 | +booting, they turn solid green. This functionality is hard-coded in the kernel |
| 14 | +and in Brickman. |
| 15 | + |
| 16 | +After the boot is complete, you can control the LEDs yourself. The LEDs live in |
| 17 | +`/sys/class/leds/`. |
| 18 | + |
| 19 | +```bash |
| 20 | +$ ls /sys/class/leds/ |
| 21 | +ev3:left:green:ev3dev ev3:right:green:ev3dev |
| 22 | +ev3:left:red:ev3dev ev3:right:red:ev3dev |
| 23 | +``` |
| 24 | + |
| 25 | +You probably noticed that _amber_ is missing here. We will get to that in a bit. |
| 26 | + |
| 27 | +Each LED has its own attributes for controlling it. We are using the standard |
| 28 | +Linux LED device class, so there is a bunch of extra stuff that it not really |
| 29 | +useful. Let's figure out what is... |
| 30 | + |
| 31 | +```bash |
| 32 | +$ ls /sys/class/leds/ev3:left\:green\:ev3dev |
| 33 | +brightness device max_brightness power subsystem trigger uevent |
| 34 | +``` |
| 35 | + |
| 36 | +{% include /style/icon.html type="info" %} |
| 37 | +You only have to escape the colons using the backslash (`\:`) when using a command |
| 38 | +line shell. The actual directory name is `ev3:left:green:ev3dev`. |
| 39 | +{: .alert .alert-info} |
| 40 | + |
| 41 | +```bash |
| 42 | +# turn the left green LED off |
| 43 | +$ echo 0 > /sys/class/leds/ev3:left\:green\:ev3dev/brightness |
| 44 | +# find out what the maximum brightness value is |
| 45 | +$ cat /sys/class/leds/ev3:left\:green\:ev3dev/max_brightness |
| 46 | +255 |
| 47 | +# turn the left green LED back on (255 means 100%) |
| 48 | +$ echo 255 > /sys/class/leds/ev3:left\:green\:ev3dev/brightness |
| 49 | +# dim the left green LED 1/2 way |
| 50 | +$ echo 127 > /sys/class/leds/ev3:left\:green\:ev3dev/brightness |
| 51 | +``` |
| 52 | + |
| 53 | +{% include /style/icon.html type="info" %} |
| 54 | +You you must be a member of the `ev3dev` group (or root) to be able to control the LEDs. |
| 55 | +{: .alert .alert-info} |
| 56 | + |
| 57 | + |
| 58 | +### Triggers |
| 59 | + |
| 60 | +Triggers can make the LED do interesting things. |
| 61 | + |
| 62 | +```bash |
| 63 | +$ cat /sys/class/leds/ev3:left\:green\:ev3dev/trigger |
| 64 | +[none] mmc0 timer heartbeat default-on transient |
| 65 | +legoev3-battery-charging-or-full legoev3-battery-charging legoev3-battery-full |
| 66 | +legoev3-battery-charging-blink-full-solid rfkill0 |
| 67 | +``` |
| 68 | + |
| 69 | +* `none` means we are manually controlling the LED with `brightness` like we just did. |
| 70 | +* `mmc0` makes the LED blink whenever there is SD card activity. This is what the |
| 71 | + LEDs were doing during boot. |
| 72 | +* `timer` makes the LED blink periodically. When we change the trigger, we get |
| 73 | + new attributes for controlling the on and off times. Times are in milliseconds. |
| 74 | + |
| 75 | + ```bash |
| 76 | + $ echo timer > /sys/class/leds/ev3:left\:green\:ev3dev/trigger |
| 77 | + $ ls /sys/class/leds/ev3:left\:green\:ev3dev |
| 78 | + brightness delay_on max_brightness subsystem uevent |
| 79 | + delay_off device power trigger |
| 80 | + $ cat /sys/class/leds/ev3:left\:green\:ev3dev/delay_on |
| 81 | + 500 |
| 82 | + $ echo 1000 > /sys/class/leds/ev3:left\:green\:ev3dev/delay_on |
| 83 | + $ echo 2000 > /sys/class/leds/ev3:left\:green\:ev3dev/delay_off |
| 84 | + ``` |
| 85 | + |
| 86 | +* `heartbeat` makes the LED blink at a rate proportional to CPU usage. |
| 87 | +* `default-on` works just like `none` except that it turns the LED on instead of |
| 88 | + off when the trigger is set. |
| 89 | +* `legoev3-battery-*` are not useful. The batteries (including the rechargeable |
| 90 | + battery pack) do not have a way of telling the EV3 what is going on, so it is |
| 91 | + assumed that the batteries are always discharging. Therefore these triggers |
| 92 | + will always turn the LED off. |
| 93 | +* `rfkill0` is the RF (radio frequency) kill switch for the built-in Bluetooth. |
| 94 | + It should make the LED indicate if the built-in Bluetooth is turned on or not. |
| 95 | + |
| 96 | + |
| 97 | +### What about amber/orange? |
| 98 | + |
| 99 | +To make the LED amber, we just have to turn on both the red and green LEDs at the same time. |
| 100 | + |
| 101 | +```bash |
| 102 | +# make left LED illuminate amber |
| 103 | +$ echo 255 > /sys/class/leds/ev3:left\:green\:ev3dev/brightness; echo 255 > /sys/class/leds/ev3:left\:red\:ev3dev/brightness |
| 104 | +# turn off left LED |
| 105 | +$ echo 0 > /sys/class/leds/ev3:left\:green\:ev3dev/brightness; echo 0 > /sys/class/leds/ev3:left\:red\:ev3dev/brightness |
| 106 | +``` |
| 107 | + |
| 108 | +How does red + green make amber? If you open up your favorite paint program that |
| 109 | +has a color chooser where you can adjust the individual red, green and blue values, |
| 110 | +we can see what is going on. Make sure blue is on zero, then change red and green |
| 111 | +both to their maximum values. You get yellow. On the EV3, the red LED is a bit |
| 112 | +stronger than than the green LED, so both LEDs at max brightness appears orange |
| 113 | +(which we are calling amber just because it is "supposed" to be sort of yellow-ish). |
| 114 | +In your paint program, if you leave red at the maximum value and start decreasing |
| 115 | +green, the color will start to turn orange and then red. So, playing around with |
| 116 | +the `brightness` values a bit, we can actually get orange and yellow. |
| 117 | + |
| 118 | +```bash |
| 119 | +# make the left LED really orange |
| 120 | +$ echo 180 > /sys/class/leds/ev3:left\:green\:ev3dev/brightness; echo 255 > /sys/class/leds/ev3:left\:red\:ev3dev/brightness |
| 121 | +# make the left LED yellow (this shows us how much stronger the red led is!) |
| 122 | +$ echo 255 > /sys/class/leds/ev3:left\:green\:ev3dev/brightness; echo 25 > /sys/class/leds/ev3:left\:red\:ev3dev/brightness |
| 123 | +``` |
0 commit comments