/*********************************************************** * * Blink a LED in Arduino-style using function from the delay * library. * (c) 2022-2024 Tomas Fryza, MIT license * * Developed using PlatformIO and AVR 8-bit Toolchain 3.6.2. * Tested on Arduino Uno board and ATmega328P, 16 MHz. * ***********************************************************/ /* Defines ------------------------------------------------*/ #define LED_GREEN PB5 // PB5 is AVR pin where green on-board LED // is connected #define SHORT_DELAY 250 // Delay in milliseconds #ifndef F_CPU # define F_CPU 16000000 // CPU frequency in Hz required for delay #endif /* Includes -----------------------------------------------*/ #include // AVR device-specific IO definitions #include // Functions for busy-wait delay loops // ----- // This part is needed to use Arduino functions but also physical pin // names. We are using Arduino-style just to simplify the first lab. #include "Arduino.h" #define PB5 13 // In Arduino world, PB5 is called "13" // ----- /* Function definitions -----------------------------------*/ /*********************************************************** * Function: Main function where the program execution begins * Purpose: Toggle one LED and use delay library. * Returns: none ***********************************************************/ int main(void) { uint8_t led_value = 0; // Local variable to keep LED status // Set pin where on-board LED is connected as output pinMode(LED_GREEN, OUTPUT); // Infinite loop while (1) { // Pause several milliseconds _delay_ms(SHORT_DELAY); // Change LED value if (led_value == 0) { led_value = 1; // Set pin to HIGH digitalWrite(LED_GREEN, HIGH); } else { led_value = 0; // Clear pin to LOW digitalWrite(LED_GREEN, LOW); } } // Will never reach this return 0; }