The story began when I visited the park last week and saw the boring Amusement in the dark, so I had an idea to add some fun by lighting it.
Idea:
the idea was to use (H01R0x) modules, the modules will work one by one in clockwise or anticlockwise direction.
the direction of lighting is controlled by a button.
Tools:
- Hexabitz RGB LED module (H01R0x)
Steps:
1. planning the array and assembling the hardware, connecting LED modules (H01R0x) in circular form, then we began in writing code.
2. Explain code:
- we defined fixed topology in all modules, it describes the connection of the modules between them, then we defined two private variables ID and button.
- in main.c file:
we gave the module in the middle a constant lighting and possibility of exchanging the messages with module number three which is connected with the button.
- According to the state of the button the direction of lighting is changed.
Code:
/**
******************************************************************************
* File Name : main.c
* Description : Main program body
******************************************************************************
*
* COPYRIGHT(c) 2015 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*pa
******************************************************************************
*/
/*
MODIFIED by Hexabitz for BitzOS (BOS) V0.2.4 - Copyright (C) 2017-2021 Hexabitz
All rights reserved
*/
/* Includes ------------------------------------------------------------------*/
#include "BOS.h"
/* Private variables ---------------------------------------------------------*/
#if _module==1
uint8_t ID=2,button3=0;
#endif
#if _module==3
uint8_t button1=0;
#endif
/* Private function prototypes -----------------------------------------------*/
/* Main functions ------------------------------------------------------------*/
int main(void)
{
/* MCU Configuration----------------------------------------------------------*/
/* Reset all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all user peripherals */
/* Initialize BitzOS */
BOS_Init();
/* Call init function for freertos objects (in freertos.c) */
MX_FREERTOS_Init();
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
while (1)
{
}
}
/*-----------------------------------------------------------*/
/* User Task */
void UserTask(void * argument)
{
#if _module==1
RGB_LED_on(50);
AddBOSvar(FMT_UINT8, (uint32_t ) &button3);
#endif
#if _module==3
AddPortButton(MOMENTARY_NO, P4);
SetButtonEvents(P4,1, 0, 0, 0, 0, 0,0, 0,0);
AddBOSvar(FMT_UINT8, (uint32_t ) &button1);
#endif
/* Infinite loop */
for(;;)
{
#if _module==1
if(button3==0)
{
messageParams[0]=50;
SendMessageToModule(ID, CODE_H01R0_ON,1);
Delay_ms(100);
SendMessageToModule(ID, CODE_H01R0_OFF,0);
Delay_ms(100);
ID++;
if(ID==8) ID=2;
}
else
{
messageParams[0]=50;
SendMessageToModule(ID, CODE_H01R0_ON,1);
Delay_ms(100);
SendMessageToModule(ID, CODE_H01R0_OFF,0);
Delay_ms(100);
ID--;
if(ID==1) ID=7;
}
#endif
}
}
#if _module==3
void buttonClickedCallback(uint8_t port)
{
if(button1==1) button1=0;
else button1=1;
WriteRemote(1, button1,1, FMT_UINT8, 100);
}
#endif
/*-----------------------------------------------------------*/
/************************ (C) COPYRIGHT HEXABITZ *****END OF FILE****/
Comments