View on GitHub

Micro Controller Peripherals and Drivers in Ada

Listing of various built-in in and external sensors and actors for micro controllers, notably AVR, ESP8266 and ESP32. We also provide driver packages in Ada and some usage examples.

LED

The simplest output device on a micro controller. A LED can typically be connected directly to a GPIO pin. Use an appropriate resistor to limit the current (100 .. 1k).

LED

Ada

GPIOs are handled as boolean variables. Off (dark) and on (light) depend on your wiring. If the LED is between a GPIO and ground the GPIO must have high level to switch the LED on. If the LED is between a GPIO and Vcc the GPIO must have low level to switch the LED on. I recommend to redefine On and Off as renamings of True and False.

-- define On and Off for a LED between GPIO and Ground.
function On return Boolean renames True;
function Off return Boolean renames False;

-- set the pin for the LED
-- there is a LED on the Arduino platform at Port B, pin 5 (digital pin 13)
LED    : Boolean renames AVR.MCU.PORTB_Bits (5);
LED_DD : Boolean renames AVR.MCU.DDRB_Bits (5);

-- set the GPIO as output
LED_DD := DD_Output; 

-- switch the LED on
LED := On;

See the files LED.ads and LED.adb in AVR-Ada for a bit more elaborate example, still producing only single assembler commands.