We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]
Rating:
Author: MIKROE
Last Updated: 2018-12-26
Package Version: 1.0.0.0
mikroSDK Library: 1.0.0.0
Category: Rotary encoder
Downloaded: 3954 times
Not followed.
License: MIT license
The Knob G click is a Click Board which features a combination of high-quality quadrature rotary encoder, and a LED ring composed of 24 individual green LEDs.
Do you want to subscribe in order to receive notifications regarding "Knob G click" changes.
Do you want to unsubscribe in order to stop receiving notifications regarding "Knob G click" changes.
Do you want to report abuse regarding "Knob G click".
Library Description
The library initializes and defines the I2C bus driver and drivers that offer a choice for writing data in the register and reads data from the register. The library includes the function for reading the Encoder position and sets a new start position. The user also has the functions for full control LEDs.
Key functions:
void knobg_setLedState(uint8_t led, uint8_t state)
- Functions for setting the led statevoid knobg_getEncoderPosition(int32_t *position, uint8_t *dir)
- Functions for getting Encoder positionvoid knobg_encoderNewStartPosition(int32_t position)
- Functions for set new start encoder positionExamples description
The application is composed of the three sections :
void applicationTask()
{
knobg_getEncoderPosition(&encoder_newPosition, &direction);
if(knobg_getSWButtonState() == 0)
{
SW_State++;
if(SW_State >= 3) SW_State = 0;
knobg_setBrightness(_KNOBG_BRIGHTNESS_ALL_LED, 0x00);
Delay_ms( 300 );
}
/* Logs position */
if(encoder_newPosition != encoder_oldPosition)
{
WordToStr(encoder_newPosition, demoText);
mikrobus_logWrite(" EnCoder position : ", _LOG_TEXT);
mikrobus_logWrite(demoText, _LOG_LINE);
}
encoder_oldPosition = encoder_newPosition;
switch(SW_State)
{
/* Brightness */
case 0:
{
cnt++;
if(cnt > 127) cnt = 0;
knobg_setBrightness(_KNOBG_BRIGHTNESS_ALL_LED, cnt);
Delay_ms( 15 );
break;
}
/* Encoder with one led*/
case 1:
{
if(encoder_newPosition > 24) knobg_encoderNewStartPosition( 1 );
if(encoder_newPosition < 1) knobg_encoderNewStartPosition( 24 );
if(direction == 1)
{
knobg_setLedState(encoder_newPosition, _KNOBG_LED_ON);
knobg_setLedState(encoder_newPosition - 1, _KNOBG_LED_OFF);
}
else
{
knobg_setLedState(encoder_newPosition, _KNOBG_LED_ON);
knobg_setLedState(encoder_newPosition + 1, _KNOBG_LED_OFF);
}
Delay_1ms();
break;
}
/* Encoder with all led */
case 2:
{
if(encoder_newPosition > 24) knobg_encoderNewStartPosition( 1 );
if(encoder_newPosition < 1) knobg_encoderNewStartPosition( 24 );
if(direction == 1)
{
knobg_setLedState(encoder_newPosition, _KNOBG_LED_ON);
}
else
{
knobg_setLedState(encoder_newPosition + 1, _KNOBG_LED_OFF);
}
Delay_1ms();
break;
}
}
}
Other mikroE Libraries used in the example:
I2C
Additional notes and information
Depending on the development board you are using, you may need USB UART click, USB UART 2 click or RS232 click to connect to your PC, for development systems with no UART to USB interface available on the board. The terminal available in all MikroElektronika compilers, or any other terminal application of your choice, can be used to read the message.