This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:software:homelab:library:pin [2010/03/16 14:23] – Helen | en:software:homelab:library:pin [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Pins ====== | ====== Pins ====== | ||
| - | Pins library provides an easy way for operating with AVR digital input-output pins. User can create a pin related variable and do all the pin operations with that variable. This way there' | + | Pins library provides an easy way for operating with AVR digital input-output pins. The user can create a pin related variable and do all the pin operations with that variable. This way there is no need to deal with the register names and bit indexes like it is done while programming in direct register access method. |
| - | ===== Data types ===== | + | ===== Data Types ===== |
| - | * **//pin//** \\ Data type to hold pin registers addresses and bit mask. To get the most efficent program, //pin// typed variables should be constant and they should be initialized at the beginning of the program code. Intializing can be done with macro function // | + | * **//pin//** \\ Data type to hold pin registers addresses and bit mask. To get the most efficent program, //pin// typed variables should be constant, and they should be initialized at the beginning of the program code. Intializing can be done with the macro function // |
| + | ===== Constants ===== | ||
| + | * **// | ||
| + | * **//LED1, LED2, LED3//** - Homelab User interface board LEDs by LED numbers | ||
| + | * **//S1, S2, S3//** - Homelab User interface board buttons | ||
| + | | ||
| ===== Functions ===== | ===== Functions ===== | ||
| Line 36: | Line 41: | ||
| * Return boolean //true// when pin is high and //false// when pin is low. | * Return boolean //true// when pin is high and //false// when pin is low. | ||
| * **//bool pin_get_debounced_value(pin pin)//** \\ | * **//bool pin_get_debounced_value(pin pin)//** \\ | ||
| - | Reads pin value through the switch debounce filter. Filtering takes at least 8 ms and may last up to 100 ms, depending | + | Reads pin value through the switch debounce filter. Filtering takes at least 8 ms and may last up to 100 ms, depending |
| * //pin// - Pin variable. | * //pin// - Pin variable. | ||
| * Return pin boolean value - //true// when pin is high and //false// when pin is low or undetermined. | * Return pin boolean value - //true// when pin is high and //false// when pin is low or undetermined. | ||
| Line 68: | Line 73: | ||
| // Setting an output pin value | // Setting an output pin value | ||
| pin_set_to(output_pin, | pin_set_to(output_pin, | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | led_on, led_off, button_read commands example | ||
| + | <code c> | ||
| + | #include < | ||
| + | |||
| + | // Homelab buttons and LEDs are predefined in the library | ||
| + | |||
| + | int main(void) | ||
| + | { | ||
| + | // Set LED pin as output | ||
| + | pin_setup_output(led_green); | ||
| + | |||
| + | // Set Button S1 pin as input | ||
| + | pin_setup_input(S1); | ||
| + | |||
| + | // Endless loop | ||
| + | while (true) | ||
| + | { | ||
| + | // If button is pressed, turn on LED, if not pressed, turn LED off. | ||
| + | if(button_read(S1) == true) | ||
| + | led_on(led_green); | ||
| + | else | ||
| + | led_off(led_green); | ||
| } | } | ||
| } | } | ||
| </ | </ | ||