/*
Name: K M AKASH
Program: C program in PICO simulator to blink the LED 10 times in the first minute,
20 times in the second minute & 30 times in third minute
*/
#include <stdio.h>
#include "pico/stdlib.h" // Provides standard library functions
#include "pico/time.h" // Provides libraries for working with time
#define LED_PIN 26
// Function to blink LED for desired number of times
void blinkLED(int times) {
for (int i = 0; i < times; i++) {
// LED ON
gpio_put(LED_PIN, 1);
// 1 Second Delay
sleep_ms(500);
// LED OFF
gpio_put(LED_PIN, 0);
// 1 Second Delay
sleep_ms(500);
}
}
// Main Function
int main() {
// Initializing all standard Input/Output facilities provided by PICO SDK
stdio_init_all();
// Initialize GPIO pin 26 for LED
gpio_init(LED_PIN);
// Set GPIO pin 26 as OUTPUT
gpio_set_dir(LED_PIN, GPIO_OUT);
// Store the start time
uint64_t start_time = time_us_64();
// Blink LED 10 times in the first minute
blinkLED(10);
// Calculate the time elapsed since the start of the minute
uint64_t elapsed_time = time_us_64() - start_time;
// Calculate the remaining time in the minute (60 seconds - elapsed time)
uint64_t remaining_time = 60000000 - elapsed_time;
// Delay until the end of the minute
sleep_us(remaining_time);
// Store the start time for the second minute
start_time = time_us_64();
// Blink LED 20 times in the second minute
blinkLED(20);
// Calculate the time elapsed since the start of the minute
elapsed_time = time_us_64() - start_time;
// Calculate the remaining time in the minute (60 seconds - elapsed time)
remaining_time = 60000000 - elapsed_time;
// Delay until the end of the minute
sleep_us(remaining_time);
// Store the start time for the third minute
start_time = time_us_64();
// Blink LED 30 times in the third minute
blinkLED(30);
// Calculate the time elapsed since the start of the minute
elapsed_time = time_us_64() - start_time;
// Calculate the remaining time in the minute (60 seconds - elapsed time)
remaining_time = 60000000 - elapsed_time;
// Delay until the end of the minute
sleep_us(remaining_time);
return 0;
}