Ashok R
Published © CC BY

Proximity Water Bottle

Proximity Water Bottle lights up itself when you search for it.

IntermediateShowcase (no instructions)24 hours1,274

Things used in this project

Story

Read more

Schematics

Block Diagram

Code

Main

C/C++
#include <project.h>
#include <stdio.h>

/*******************************************************************************
* Function Name: main
********************************************************************************
*
*  The main function performs the following actions:
*   1. Sets up the Timer and UART components.
*   2. Checks for changes in the current count. The counter increments each time the kit button SW2 is pressed. 
*       I.  LED is flashed to show that count has changed
*       II. The current count is printed via UART to terminal.
*
*******************************************************************************/
int main(void)
{
    /* Buffer for string conversion */
    char snum[32];

    /* Initializing currentCount*/
    uint32 prevCount = 0xFFFF;

    /* Enable global interrupts. */
	CyGlobalIntEnable; 
    
    /* Start the Timer component */
    Timer_Start();
    
    /* Starts the UART component */
    UART_Start();
    UART_UartPutString("PIR Water Bottel \r\n");
    
    for(;;)
    {
        uint32 currentCount = Timer_ReadCounter();
        /* When the count changes in the counter */
        if(currentCount > 3)
        {
            currentCount = 0;
            Timer_WriteCounter(0);
            /* Sending current count to UART to be printed in terminal */
                        
            /* Delay to show LED in ON state before going to OFF state */

            LED_RED_Write(1);
            LED_GREEN_Write(1);
            CyDelay(5000);
            LED_GREEN_Write(0);
            LED_RED_Write(0);
            
            /* Vibration motor */
           currentCount = 0;
           Timer_WriteCounter(0);
           Timer_StartMotor(MOTOR_RATE_HZ);

        }
        
        if(Clock_Ticks()> ALERT_TIME){
          
           currentCount = 0;
           Timer_WriteCounter(0);
           Timer_StartBlink(LED_BLINKRATE_HZ);
          
        }
    }
}

Credits

Ashok R

Ashok R

37 projects • 102 followers
Hobbyist/Engineer/Director/Animatior

Comments