#include <wiringPi.h>
#include <softPwm.h>
#include <stdio.h>
#include <unistd.h>
// GPIO18 corresponds to pin 1 on
#define LED_PIN_18 1
// GPIO5 corresponds to pin 24 on
#define LED_PIN_5 24
int main()
{
if (wiringPiSetup() == -1)
{
return 1;
}
// Set the GPIO pins
pinMode(LED_PIN_18, OUTPUT);
pinMode(LED_PIN_5, OUTPUT);
// Gradually increase brightness over 5 seconds
// Initialize PWM on GPIO18
softPwmCreate(LED_PIN_18, 0, 100);
// Initialize PWM on GPIO5
softPwmCreate(LED_PIN_5, 0, 100);
for (int duty_cycle = 0; duty_cycle <= 100; duty_cycle += 20)
{
softPwmWrite(LED_PIN_18, duty_cycle);
softPwmWrite(LED_PIN_5, duty_cycle);
sleep(1);
}
// Turn off LEDs for 2 seconds
softPwmWrite(LED_PIN_18, 0);
softPwmWrite(LED_PIN_5, 0);
sleep(2);
// Increase to full brightness over 1 second
for (int duty_cycle = 0; duty_cycle <= 50; duty_cycle += 10)
{
softPwmWrite(LED_PIN_18, duty_cycle);
softPwmWrite(LED_PIN_5, duty_cycle);
// Sleep for 0.5 seconds
usleep(500000);
}
// Repeat steps 3-5 four times
for (int repeat = 0; repeat < 4; repeat++)
{
softPwmWrite(LED_PIN_18, 0);
softPwmWrite(LED_PIN_5, 0);
sleep(2);
for (int duty_cycle = 0; duty_cycle <= 50; duty_cycle += 10) {
softPwmWrite(LED_PIN_18, duty_cycle);
softPwmWrite(LED_PIN_5, duty_cycle);
// Sleep for 0.5 seconds
usleep(500000);
}
}
// Permanently turn off
softPwmWrite(LED_PIN_18, 0);
softPwmWrite(LED_PIN_5, 0);
return 0;
}