Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 4 | ||||
| × | 4 | ||||
| × | 1 | ||||
| × | 4 | ||||
| × | 2 | ||||
| × | 4 | ||||
Software apps and online services | ||||||
| ||||||
Hand tools and fabrication machines | ||||||
| ||||||
|
In the long past I saw my mom waking up to turning on the water pump at midnight almost everyday and waiting to full fill the water box and then, back to sleep, to go work few times later.
As a child I didn't happy watching this situation. So, when I saw an article, reading an electronic magazine called by "APE - Aprendendo e praticando eletrônica", there was a project explaining how to build a water level using operational amplifier, that time is was LM741. I bought it and installed in my home. I did not know anything about electronic, everything I have learnt was reading the project path on this article.
When my mom has arrived at the end of the day the project was in working and filling the water tank accordangly, turning on and off the water pump.
Since that time and nowadays, electronics projects are part of my life.
Hello, my name is Andre Pereira da Silva, I am industrial technician, have electronic engineering course on UERJ and studying Physics on UFRJ, Rio de Janeiro, Brazil.
Here we are one of the most poor country known in the world, with severe inequalities and maybe, the worst educational system, carrying an historical cultor for corruption in any level of the society. But this is changing. More and more people here are trying to do a better Brazil to the world. Working in good education system, in tecnology and changing the politician culture to achieve a knowledgment to more people we can.
If you are planning to come to Brazil, take care. But you will find many good persons to talk about tecnology, like me.
modified file "led output"
C/C++In KDS_V3 uoy need to import the project and find those files to change, I mean, "pin_mux, board and gpio_led_output"
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o 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.
*
* o Neither the name of Freescale Semiconductor, Inc. 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.
*/
#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_gpio.h"
#include "clock_config.h"
#include "pin_mux.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define BOARD_LED_GPIO BOARD_LED_RED_GPIO
#define BOARD_LED_GPIO_PIN BOARD_LED_RED_GPIO_PIN
// relay output
#define RL1 BOARD_rl1_GPIO
#define RL1_PIN BOARD_rl1_PIN
#define RL2 BOARD_rl2_GPIO
#define RL2_PIN BOARD_rl2_PIN
// led definitions.
#define LED1 BOARD_LED1_GPIO
#define PIND1 BOARD_LED1_PIN
#define LED2 BOARD_LED2_GPIO
#define PIND2 BOARD_LED2_PIN
#define LED3 BOARD_LED3_GPIO
#define PIND3 BOARD_LED3_PIN
#define LED4 BOARD_LED4_GPIO
#define PIND4 BOARD_LED4_PIN
// Level definitions
#define LEVEL1 BOARD_LEVEL1_GPIO
#define PINB1 BOARD_LEVEL1_PIN
#define LEVEL2 BOARD_LEVEL2_GPIO
#define PINB2 BOARD_LEVEL2_PIN
#define LEVEL3 BOARD_LEVEL3_GPIO
#define PINB3 BOARD_LEVEL3_PIN
#define LEVEL4 BOARD_LEVEL4_GPIO
#define PINB4 BOARD_LEVEL4_PIN
/*******************************************************************************
* Prototypes
******************************************************************************/
/*!
* @brief delay a while.
*/
void delay(void);
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
void delay(void)
{
volatile uint32_t i = 0;
for (i = 0; i < 800000; ++i)
{
__asm("NOP"); /* delay */
}
}
/*!
* @brief Main function
*/
int main(void)
{
/* Define the init structure for the output LED pin*/
gpio_pin_config_t led_config =
{
kGPIO_DigitalOutput,
0,
};
gpio_pin_config_t level_config =
{
kGPIO_DigitalInput,
1,
};
/* Board pin, clock, debug console init */
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
/* Print a note to terminal. */
PRINTF("\r\n GPIO Driver example\r\n");
PRINTF("\r\n The LED is taking turns to shine.\r\n");
/* Init output LED GPIO. */
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &led_config);
GPIO_PinInit(LED1, PIND1, &led_config);
GPIO_PinInit(LED2, PIND2, &led_config);
GPIO_PinInit(LED3, PIND3, &led_config);
GPIO_PinInit(LED4, PIND4, &led_config);
GPIO_PinInit(LEVEL1, PINB1, &level_config);
GPIO_PinInit(LEVEL2, PINB2, &level_config);
GPIO_PinInit(LEVEL3, PINB3, &level_config);
GPIO_PinInit(LEVEL4, PINB4, &level_config);
while (1)
{
/*********************************************************************************
*This part is to read the four levels of liquid and turns on the led accordantly*
********************************************************************************/
//reading level one and lit led one.
if(!GPIO_ReadPinInput(LEVEL1,PINB1)){
GPIO_WritePinOutput(LED1,PIND1,1);
delay();
}
else
{
GPIO_WritePinOutput(LED1,PIND1,0);
delay();
}
//reading level two ant lit the led two.
if(!GPIO_ReadPinInput(LEVEL2,PINB2)){
GPIO_WritePinOutput(LED2,PIND2,1);
delay();
}
else
{
GPIO_WritePinOutput(LED2,PIND2,0);
delay();
}
//reading level three and lit the led three.
if(!GPIO_ReadPinInput(LEVEL3,PINB3)){
GPIO_WritePinOutput(LED4,PIND4,1);
delay();
}
else
{
GPIO_WritePinOutput(LED4,PIND4,0);
delay();
}
//reading level four and lit the led four.
if(!GPIO_ReadPinInput(LEVEL4,PINB4)){
GPIO_WritePinOutput(LED3,PIND3,1);
delay();
}
else
{
GPIO_WritePinOutput(LED3,PIND3,0);
delay();
}
//
// delay();
// GPIO_TogglePinsOutput(LED1,1U << PIND1);
// GPIO_TogglePinsOutput(BOARD_LED_GPIO, 1U << BOARD_LED_GPIO_PIN);
}
}
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o 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.
*
* o Neither the name of Freescale Semiconductor, Inc. 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.
*/
#include "fsl_common.h"
#include "fsl_port.h"
#include "pin_mux.h"
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
void BOARD_InitPins(void)
{
/* Debug uart port mux config */
/* Enable uart port clock */
CLOCK_EnableClock(kCLOCK_PortC);
CLOCK_EnableClock(kCLOCK_PortB);
CLOCK_EnableClock(kCLOCK_PortD);
/* Affects PORTC_PCR14 register */
PORT_SetPinMux(PORTC, 14U, kPORT_MuxAlt3);
/* Affects PORTC_PCR15 register */
PORT_SetPinMux(PORTC, 15U, kPORT_MuxAlt3);
port_pin_config_t pinConfig = {0};
pinConfig.pullSelect = kPORT_PullUp;
PORT_SetPinConfig(PORTB, 0U, &pinConfig);
PORT_SetPinConfig(PORTB, 1U, &pinConfig);
PORT_SetPinConfig(PORTB, 2U, &pinConfig);
PORT_SetPinConfig(PORTB, 3U, &pinConfig);
/* Led pin mux Configuration */
//PORT_SetPinMux(PORTC, 8U, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTD, 0U, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTD, 1U, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTD, 2U, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTD, 3U, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTB, 0U, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTB, 1U, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTB, 2U, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTB, 3U, kPORT_MuxAsGpio);
}
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o 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.
*
* o Neither the name of Freescale Semiconductor, Inc. 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.
*/
#ifndef _BOARD_H_
#define _BOARD_H_
#include "clock_config.h"
#include "fsl_gpio.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @brief The board name */
#define BOARD_NAME "FRDM-K82F"
/*! @brief The UART to use for debug messages. */
#define BOARD_USE_UART
#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_LPUART
#define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART4
#define BOARD_DEBUG_UART_CLKSRC kCLOCK_Osc0ErClk
#define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetOsc0ErClkFreq()
#define BOARD_UART_IRQ LPUART4_IRQn
#define BOARD_UART_IRQ_HANDLER LPUART4_IRQHandler
#ifndef BOARD_DEBUG_UART_BAUDRATE
#define BOARD_DEBUG_UART_BAUDRATE 115200
#endif /* BOARD_DEBUG_UART_BAUDRATE */
/*! @brief The i2c instance used for i2c connection by default */
#define BOARD_I2C_BASEADDR I2C3
/*! @brief The Flextimer instance/channel used for board */
#define BOARD_FTM_BASEADDR FTM3
#define BOARD_FTM_CHANNEL 4U
#define BOARD_FTM_X_CHANNEL 4U
#define BOARD_FTM_Y_CHANNEL 5U
#define BOARD_FTM_PERIOD_HZ 100
#define BOARD_FTM_IRQ_HANDLER FTM3_IRQHandler
#define BOARD_FTM_IRQ_VECTOR FTM3_IRQn
/*! @brief The bubble level demo information */
#define BOARD_FXOS8700_ADDR 0x1C
#define BOARD_ACCEL_ADDR BOARD_FXOS8700_ADDR
#define BOARD_ACCEL_BAUDRATE 100
#define BOARD_ACCEL_I2C_BASEADDR I2C3
/*! @brief The TPM instance/channel used for board */
#define BOARD_TPM_BASEADDR TPM2
#define BOARD_TPM_CHANNEL 0U
/*! @brief The FlexBus instance used for board.*/
#define BOARD_FLEXBUS_BASEADDR FB
#define BOARD_TSI_ELECTRODE_CNT 2U
/*! @brief Indexes of the TSI channels for on board electrodes */
#define BOARD_TSI_ELECTRODE_1 11U
#define BOARD_TSI_ELECTRODE_2 12U
/*! @brief The SDHC instance/channel used for board */
#define BOARD_SDHC_BASEADDR SDHC
/*! @brief The CMP instance/channel used for board. */
#define BOARD_CMP_BASEADDR CMP1
#define BOARD_CMP_CHANNEL 3U
/*! @brief The i2c instance used for sai demo */
#define BOARD_SAI_DEMO_I2C_BASEADDR I2C0
/*! @brief The rtc instance used for rtc_func */
#define BOARD_RTC_FUNC_BASEADDR RTC
/*! @brief If connected the TWR_MEM, this is spi sd card */
#define BOARD_SDCARD_CARD_DETECTION_GPIO GPIOD
#define BOARD_SDCARD_CARD_DETECTION_GPIO_PORT PORTD
#define SDCARD_CARD_DETECTION_GPIO_PIN 15U
#define SDCARD_CARD_WRITE_PROTECTION_GPIO GPIOC
#define SDCARD_CARD_WRITE_PROTECTION_GPIO_PORT PORTC
#define SDCARD_CARD_WRITE_PROTECTION_GPIO_PIN 13U
#define SDCARD_SPI_HW_BASEADDR SPI1
#define SDCARD_CARD_INSERTED 0U
/*! @brief Define the port interrupt number for the board switches */
#define BOARD_SW2_GPIO GPIOA
#define BOARD_SW2_PORT PORTA
#define BOARD_SW2_GPIO_PIN 4U
#define BOARD_SW2_IRQ PORTA_IRQn
#define BOARD_SW2_IRQ_HANDLER PORTA_IRQHandler
#define BOARD_SW2_NAME "SW2"
#define BOARD_SW3_GPIO GPIOC
#define BOARD_SW3_PORT PORTC
#define BOARD_SW3_GPIO_PIN 6U
#define BOARD_SW3_IRQ PORTC_IRQn
#define BOARD_SW3_IRQ_HANDLER PORTC_IRQHandler
#define BOARD_SW3_NAME "SW3"
/* Board led color mapping */
#define LOGIC_LED_ON 0U
#define LOGIC_LED_OFF 1U
#define BOARD_LED_RED_GPIO GPIOC
#define BOARD_LED_RED_GPIO_PORT PORTC
#define BOARD_LED_RED_GPIO_PIN 8U
#define BOARD_LED_GREEN_GPIO GPIOC
#define BOARD_LED_GREEN_GPIO_PORT PORTC
#define BOARD_LED_GREEN_GPIO_PIN 9U
#define BOARD_LED_BLUE_GPIO GPIOC
#define BOARD_LED_BLUE_GPIO_PORT PORTC
#define BOARD_LED_BLUE_GPIO_PIN 10U
//---------------------------------------------------------------------
/* Board level sensor */
#define BOARD_rl1_GPIO GPIOC //Relay1 for actuate any motor as example.
#define BOARD_rl1_PORT PORTC
#define BOARD_rl1_PIN 5U
#define BOARD_rl2_GPIO GPIOC // Relay2 for actuate some auxiliary motor.
#define BOARD_rl2_PORT PORTC
#define BOARD_rl2_PIN 3U
// Led output to indicate which level is on or off.
#define BOARD_LED1_GPIO GPIOD
#define BOARD_LED1_PORT PORTD
#define BOARD_LED1_PIN 0U
#define BOARD_LED2_GPIO GPIOD
#define BOARD_LED2_PORT PORTD
#define BOARD_LED2_PIN 1U
#define BOARD_LED3_GPIO GPIOD
#define BOARD_LED3_PORT PORTD
#define BOARD_LED3_PIN 2U
#define BOARD_LED4_GPIO GPIOD
#define BOARD_LED4_PORT PORTD
#define BOARD_LED4_PIN 3U
// level input to indicate which level is actuated.
#define BOARD_LEVEL1_GPIO GPIOB
#define BOARD_LEVEL1_PORT PORTB
#define BOARD_LEVEL1_PIN 0U
#define BOARD_LEVEL2_GPIO GPIOB
#define BOARD_LEVEL2_PORT PORTB
#define BOARD_LEVEL2_PIN 1U
#define BOARD_LEVEL3_GPIO GPIOB
#define BOARD_LEVEL3_PORT PORTB
#define BOARD_LEVEL3_PIN 2U
#define BOARD_LEVEL4_GPIO GPIOB
#define BOARD_LEVEL4_PORT PORTB
#define BOARD_LEVEL4_PIN 3U
//--------------------------------------------------
/* FLEXIO */
#define BOARD_FLEXIO_I2C_INSTANCE (3)
#define BOARD_FLEXIO_I2C_INSTANCE_BASE (I2C3)
#define BOARD_FLEXIO_INSTANCE (0)
#define BOARD_FLEXIO_INSTANCE_BASE (FLEXIO0)
#define BOARD_FLEXIO_DATA_PINS (8)
#define BOARD_FLEXIO_DATA_PIN_START_INDEX (4)
#define BOARD_FLEXIO_DATA_PIN_END_INDEX (11)
#define BOARD_FLEXIO_PCLK_PIN_INDEX (0)
#define BOARD_FLEXIO_HREF_PIN_INDEX (3)
#define BOARD_FLEXIO_VSYNC_PORT_INDEX (1)
#define BOARD_FLEXIO_VSYNC_PIN_INDEX (2)
#define BOARD_FLEXIO_CLCK_OUT_PORT_INDEX (2)
#define BOARD_FLEXIO_CLCK_OUT_PIN_INDEX (3)
#define BOARD_FLEXIO_RESET_PORT_INDEX (2)
#define BOARD_FLEXIO_RESET_PIN_INDEX (8)
#define TICKLESS_LPTMR_BASE_PTR LPTMR0
#define TICKLESS_LPTMR_IRQn LPTMR0_LPTMR1_IRQn
#define vPortLptmrIsr LPTMR0_LPTMR1_IRQHandler
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*******************************************************************************
* API
******************************************************************************/
void BOARD_InitDebugConsole(void);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* _BOARD_H_ */
Comments