SliceKit GPIO Example Applications
led_value = led_value & 0 x0F ;
if( led_value == 15)
{
led_value =0 x0E ;
}
}
if( button_press_1 == BUTTON_PRESS_VALUE -1) // Button 2 is pressed
{
data1 [0]=0; data1 [1]=0;
i2c_master_rx (0 x28 , data1 , 2, i2cOne ); // Read ADC value using I2C
>
read
printstrln (" Reading Temperature value .... ");
data1 [0]= data1 [0]&0 x0F ;
adc_value =( data1 [0] < <6) |( data1 [1] > >2);
printstr (" Temperature is :");
printintln ( linear_interpolation ( adc_value ));
}
button =1;
break ;
}
After recognising the valid push then it checks if Button 1 is pressed or Button 2 is pressed. IF
Button 1 is pressed then, the application reads the status of LEDs and shift the position of the
LEDs to left by 1. If Button 2 is pressed, then the applciation reads the contents of ADC register
using I2C read instruction and input the ADC value to linear interpolation function as shown
below.
int linear_interpolation ( int adc_value )
{
int i=0,x1 ,y1 ,x2 ,y2 , temper ;
while ( adc_value < TEMPERATURE_LUT [i ][1])
{
i ++;
}
//:: Formula start
// Calculating Linear interpolation using the formula y=y1 +(x-x1)*(y2 -y1)/(x2 -x1)
//:: Formula
x1= TEMPERATURE_LUT [i -1][1];
y1= TEMPERATURE_LUT [i -1][0];
x2= TEMPERATURE_LUT [i ][1];
y2= TEMPERATURE_LUT [i ][0];
temper =y1 +((( adc_value -x1)*(y2 -y1))/(x2 -x1));
return temper ;// Return Temperature value
}
The linear intepolation function calculates the linear interpolation value using the following
formula and returns the temperature value from temperature look up table.
// Calculating Linear interpolation using the formula y=y1 +(x-x1)*(y2 -y1)/(x2 -x1)
int TEMPERATURE_LUT [][2]= // Temperature Look up table
{
{ -10 ,845} ,{ -5 ,808} ,{0 ,765} ,{5 ,718} ,{10 ,668} ,{15 ,614} ,{20 ,559} ,{25 ,504} ,{30 ,450} ,{35 ,399} ,
>
{40 ,352} ,{45 ,308} ,{50 ,269} ,{55 ,233} ,{60 ,202}
REV A