Skip to content

Commit

Permalink
projects/01drv_rgbled_pwm: add example application for rgbled pwm lib…
Browse files Browse the repository at this point in the history
…rary
  • Loading branch information
aabadie committed Sep 6, 2023
1 parent 70a4d0c commit e25fea1
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
59 changes: 59 additions & 0 deletions projects/01drv_rgbled_pwm/01drv_rgbled_pwm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @file 01bsp_rgbled_pwm.c
* @author Alexandre Abadie <[email protected]>
* @brief This is a short example of how to interface with the RGB LED in the DotBot shield.
*
* Load this program on your board. The LEDs should start blinking different colors.
*
* @copyright Inria, 2023
*
*/
#include <nrf.h>
#include <stdio.h>
#include <stdlib.h>
#include "board.h"
#include "rgbled_pwm.h"
#include "timer.h"
#include "board_config.h"

//=========================== variables ========================================

#ifdef DB_RGB_LED_PWM_RED_PORT
static const db_rgbled_pwm_conf_t rgbled_pwm_conf = {
.pins = {
{ .port = DB_RGB_LED_PWM_RED_PORT, .pin = DB_RGB_LED_PWM_RED_PIN },
{ .port = DB_RGB_LED_PWM_GREEN_PORT, .pin = DB_RGB_LED_PWM_GREEN_PIN },
{ .port = DB_RGB_LED_PWM_BLUE_PORT, .pin = DB_RGB_LED_PWM_BLUE_PIN },
}
};
#endif

//=========================== main =============================================

int main(void) {
db_board_init();
db_timer_init();
#ifdef DB_RGB_LED_PWM_RED_PORT
db_rgbled_pwm_init(&rgbled_pwm_conf);
#endif

/* Change RGB colors in a loop */
while (1) {
#ifdef DB_RGB_LED_PWM_RED_PORT
db_rgbled_pwm_set_color(255, 0, 0);
db_timer_delay_s(2);
db_rgbled_pwm_set_color(0, 255, 0);
db_timer_delay_s(2);
db_rgbled_pwm_set_color(0, 0, 255);
db_timer_delay_s(2);
db_rgbled_pwm_set_color(255, 255, 0);
db_timer_delay_s(2);
db_rgbled_pwm_set_color(0, 255, 255);
db_timer_delay_s(2);
db_rgbled_pwm_set_color(255, 0, 255);
#else
puts("RGB LED pwm not supported!");
#endif
db_timer_delay_s(2);
}
}
4 changes: 4 additions & 0 deletions projects/01drv_rgbled_pwm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# RGB LED board support package usage example

Loading this app onto the DotBot board will change the RGB LED color every 2
seconds in a loop.
39 changes: 39 additions & 0 deletions projects/projects-bsp-drv.emProject
Original file line number Diff line number Diff line change
Expand Up @@ -744,4 +744,43 @@
<file file_name="$(SeggerThumbStartup)" />
</folder>
</project>
<project Name="01drv_rgbled_pwm">
<configuration
Name="Common"
project_dependencies="00bsp_dotbot_board(bsp);00bsp_timer(bsp);00drv_rgbled_pwm(drv)"
project_directory="01drv_rgbled_pwm"
project_type="Executable" />
<folder Name="Device Files">
<file file_name="$(DeviceCommonHeaderFile)" />
<file file_name="$(DeviceHeaderFile)" />
<file file_name="$(DeviceSystemFile)">
<configuration
Name="Common"
default_code_section=".init"
default_const_section=".init_rodata" />
</file>
</folder>
<folder Name="Script Files">
<file file_name="$(DeviceLinkerScript)">
<configuration Name="Common" file_type="Linker Script" />
</file>
<file file_name="$(DeviceMemoryMap)">
<configuration Name="Common" file_type="Memory Map" />
</file>
<file file_name="../../nRF/Scripts/nRF_Target.js">
<configuration Name="Common" file_type="Reset Script" />
</file>
</folder>
<folder Name="Source Files">
<configuration Name="Common" filter="c;cpp;cxx;cc;h;s;asm;inc" />
<file file_name="01drv_rgbled_pwm.c" />
</folder>
<folder Name="System Files">
<file file_name="$(DeviceCommonVectorsFile)" />
<file file_name="$(DeviceVectorsFile)">
<configuration Name="Common" file_type="Assembly" />
</file>
<file file_name="$(SeggerThumbStartup)" />
</folder>
</project>
</solution>

0 comments on commit e25fea1

Please sign in to comment.