Najib.M Kassab
Published © GPL3+

Hold the drop

Hold-the-drop project shows the robustness and reliability of the connection between modules of Hexabitz.

IntermediateFull instructions provided5 hours120
Hold the drop

Things used in this project

Hardware components

Hexabitz RGB LED Module (H01R00)
Hexabitz RGB LED Module (H01R00)
×12
Hexabitz 3.3V/1A DC-DC Power Supply Module (H03R00)
Hexabitz 3.3V/1A DC-DC Power Supply Module (H03R00)
×1
Hexabitz 3-axis IMU and 3-axis Compass Module (H0BR40)
Hexabitz 3-axis IMU and 3-axis Compass Module (H0BR40)
×1
Push-button
×1
Hexabitz H00R0 Silkscreen Artwork
×1
Bench Power Supply, Linear DC
Bench Power Supply, Linear DC
×1
Li-Ion Battery 100mAh
Li-Ion Battery 100mAh
×1

Story

Read more

Code

H0BR40

C/C++
this code is for IMU Module
/**
  ******************************************************************************
  * 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.
  *
  ******************************************************************************
  */
	
/*
		MODIFIED by Hexabitz for BitzOS (BOS) V0.1.6 - Copyright (C) 2017-2019 Hexabitz
    All rights reserved
*/

/* Includes ------------------------------------------------------------------*/
#include "BOS.h"


/* Private variables ---------------------------------------------------------*/
volatile int16_t state;
volatile int16_t Response1;
volatile bool delay1;
static float x,y,z;
static int Roll,Pitch;
static float velocity;
static int id_new;
static int id_old;

/* 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)
{
BOS.trace=TRACE_NONE;
BOS.response=BOS_RESPONSE_NONE;
AddBOSvar(FMT_INT16,(uint32_t) &state);
AddBOSvar(FMT_INT16,(uint32_t) &Response1);	
AddBOSvar(FMT_BOOL,(uint32_t) &delay1);
	
  /* Infinite loop */
  for(;;)
	{	begin:
	if(delay1==true)
	{velocity=0.5;
	}
	else
	{
	velocity=1;
	}
	
SampleAccG(&x,&y,&z);
Roll = atan2(y, z) * 57.3*velocity;
Pitch = atan2(-x, sqrt(y*y + z*z)) * 57.3;	

	if(Roll>=2 && Roll<8)
	{
		if(Pitch>=3)
		{
			
			id_new=3;
		}
		else if (Pitch<=-3)
		{id_new=11;
		}
		else
		{
			id_new=7;
		}
	}
		else if(Roll>=8 && Roll<16)
		{
			if(Pitch>=3)
			{id_new=2;

			}
			else if(Pitch<=-3)
			{
				id_new=10;

			}
			else
			{
				
        id_new=6;

			}
		}
			else if(Roll<=-2 && Roll>-8)
			{
				if(Pitch>=3)
				{id_new=4;

				}
				else if(Pitch<=-3)
				{id_new=12;
					   

				}
				else
				{
					id_new=8;
					   

				}
			}
				else if(Roll<=-8 && Roll>-16)
				{
					if(Pitch>=3)
					{
						id_new=5;
						  

					}
					else if(Pitch<=-3)
					{
						id_new=13;
						    

					}
					else
					{id_new=9;
						

					}
				}
			
          else
          {IND_blink(100);
						SendMessageToModule(id_old,CODE_H01R0_OFF,0);
						goto begin;
									 }
if(id_old!=id_new && id_old!=0)
{ do
	{state=2;
		WriteRemote(id_old, (uint32_t) &state, 1, FMT_INT16, 0);
		Delay_ms(50);
	}
	while(Response1!=id_old);
			}						
do
{state=1;
	WriteRemote(id_new, (uint32_t) &state, 1, FMT_INT16, 0);
	Delay_ms(50);
}
while(Response1!=id_new);
Response1=0;
id_old=id_new;
}
}

/*-----------------------------------------------------------*/

/************************ (C) COPYRIGHT HEXABITZ *****END OF FILE****/

H01R0

C/C++
this code is for H01R0 Module RGB_Leds
/**
  ******************************************************************************
  * 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.
  *
  ******************************************************************************
  */
	
/*
		MODIFIED by Hexabitz for BitzOS (BOS) V0.1.6 - Copyright (C) 2017-2019 Hexabitz
    All rights reserved
*/

/* Includes ------------------------------------------------------------------*/
#include "BOS.h"


/* Private variables ---------------------------------------------------------*/
volatile int16_t state;
volatile int16_t Response1;
volatile bool delay1;

/* 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)
{BOS.trace=TRACE_NONE;
AddBOSvar(FMT_INT16,(uint32_t) &state);
AddBOSvar(FMT_INT16,(uint32_t) &Response1);	
	AddBOSvar(FMT_BOOL,(uint32_t) &delay1);	
BOS.response = BOS_RESPONSE_NONE;
	#if _module==6
	AddPortButton(MOMENTARY_NO,P4);
	SetButtonEvents(P4,1,1,0,0,0,0,0,0,0);
	#endif
 /* Infinite loop */
  for(;;)
  {
		#if _module==2

if(state==1)
		{	RGB_LED_on(50);
			Response1=2;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;
			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=2;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;
		}	
#endif
		#if _module==3

if(state==1)
		{	RGB_LED_on(50);
			Response1=3;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;
			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=3;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;
	
		}	
#endif
		#if _module==4

if(state==1)
		{	RGB_LED_on(50);
			Response1=4;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;

			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=4;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;
		
		}	
#endif
		#if _module==5

if(state==1)
		{	RGB_LED_on(50);
			Response1=5;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;

			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=5;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;
			
		}	
#endif
		#if _module==6

if(state==1)
		{	RGB_LED_on(50);
			Response1=6;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;

			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=6;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;
			
		}	
#endif
		#if _module==7

if(state==1)
		{	RGB_LED_on(50);
			Response1=7;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;

			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=7;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;
			
		}	
#endif
		#if _module==8

if(state==1)
		{	RGB_LED_on(50);
			Response1=8;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;

			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=8;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;

		}	
#endif
		#if _module==9

if(state==1)
		{	RGB_LED_on(50);
			Response1=9;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;

			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=9;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;
			
		}	
#endif
		#if _module==10

if(state==1)
		{	RGB_LED_on(50);
			Response1=10;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;

			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=10;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;
			
		}	
#endif
#if _module==11

if(state==1)
		{	RGB_LED_on(50);
			Response1=11;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;

			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=11;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
	
state=0;
		}	
#endif

#if _module==12

if(state==1)
		{	RGB_LED_on(50);
			Response1=12;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;

			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=12;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);		
state=0;
		}	
#endif
		#if _module==13

if(state==1)
		{	RGB_LED_on(50);
			Response1=13;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);
			state=0;
	
			}		
		else if(state==2)
		{
RGB_LED_off();
			Response1=13;
				WriteRemote(1, (uint32_t) &Response1, 2, FMT_INT16, 0);	
state=0;
			
		}	
#endif
	}}
	 void buttonClickedCallback(uint8_t port)
	 {
	 delay1=true;
	 IND_blink(10);
		 WriteRemote(1, (uint32_t) &delay1, 3, FMT_BOOL, 0);
	 }
	void buttonDblClickedCallback(uint8_t port)
	{delay1=false;
	 IND_blink(10);
		 WriteRemote(1, (uint32_t) &delay1, 3, FMT_BOOL, 0);
	}
	 
/*-----------------------------------------------------------*/

/************************ (C) COPYRIGHT HEXABITZ *****END OF FILE****/

Credits

Najib.M Kassab

Najib.M Kassab

1 project • 1 follower

Comments