Mohamad Khatib
Published © GPL3+

Optical Tracking System using Hexabitz Modules

This project is used to detect light and give a control signal to a servo motor that moves in the direction of the light and responds to it

BeginnerFull instructions provided5 hours216
Optical Tracking System using Hexabitz Modules

Things used in this project

Story

Read more

Code

Optical Tracking System using Hexabitz Modules

C/C++
Use Hexabitz V0.2.6 release firmware and build this code
https://github.com/HexabitzPlatform/H0AR9x-Firmware
/*
 BitzOS (BOS) V0.2.6 - Copyright (C) 2017-2021 Hexabitz
 All rights reserved

 File Name     : main.c
 Description   : Main program body.
 */
/* Includes ------------------------------------------------------------------*/
#include "BOS.h"
#include "stdio.h"
/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

uint16_t red, green, blue;

int colores();

/* Main function ------------------------------------------------------------*/
int colores(){


	if (red+green+blue > 160 && red+green+blue < 400 )  //70
			return 1;

	else if (red+green+blue > 800 && red+green+blue < 1700)     //90
			return 2;

	else if (red+green+blue < 160)   //135
		return 3;

	else if (red+green+blue > 1900 && red+green+blue < 7000)     //180
		return 4;

}

int main(void) {

	Module_Init();		//Initialize Module &  BitzOS

	//Don't place your code here.
	for (;;) {
	}
}

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

/* User Task */
void UserTask(void *argument) {

	// put your code here, to run repeatedly.

	while (1) {

		SampleColor(&red, &green, &blue);

		int x = colores();

		switch (x) {

		case 1:   //70

			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, SET);
			Delay_ms(1);
			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, RESET);
			Delay_ms(19);
			Delay_ms(50);

			while (red + green + blue > 175)
			{
				SampleColor(&red, &green, &blue);
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, SET);
				Delay_ms(1);
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, RESET);
				Delay_ms(19);
				Delay_ms(50);
			}
			break;

		case 2:  //90

			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, SET);
			Delay_us(1000);
			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, RESET);
			Delay_us(19000);
			Delay_ms(50);

			while (red + green + blue > 200)
			{
				SampleColor(&red, &green, &blue);
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, SET);
				Delay_us(1000);
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, RESET);
				Delay_us(19000);
				Delay_ms(50);
			}
			break;

		case 3:  //135

			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, SET);
			Delay_us(1250);                                    //Delay_ms(2);
			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, RESET);
			Delay_us(18750);                                 //	Delay_ms(18);
			Delay_ms(50);
			break;

		case 4:  //180

			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, SET);
			Delay_us(2000);
			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, RESET);
			Delay_us(18000);
			Delay_ms(50);

			while (red + green + blue > 300)
			{
				SampleColor(&red, &green, &blue);
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, SET);
				Delay_us(2000);
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, RESET);
				Delay_us(18000);
				Delay_ms(50);
			}
			break;
		}

	}
}

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

Credits

Mohamad Khatib

Mohamad Khatib

3 projects • 4 followers

Comments