Example #1
0
float Light::readEv()
{
    float lux;
    static float lastReading;

    if(!initialized) return 0;

    if(paused || skipTask) return lastReading;

    lux = readLux();

	  method = 0;

    float ev = libc_log2(lux);

    ev *= 3;
    ev += 30;

    if(filterIndex < 0) // initialize buffer
    {
      for(uint8_t i = 0; i < FILTER_LENGTH; i++) filter[i] = ev;
      filterIndex = 0;
    }
    else // circular buffer
    {
      if(filterIndex < FILTER_LENGTH - 1) filterIndex++; else filterIndex = 0;
      filter[filterIndex] = ev;
    }

    ev = arrayMedian(filter, FILTER_LENGTH);

    lastReading = ev;

    return ev;
}
Example #2
0
int main(){
	Node head1(3);
	Node n1(2);
	Node n2(1);
	Node n3(5);
	Node n4(6);
	head1.Left=&n1;
	head1.Right=&n3;
	n1.Left=&n2;
	n3.Right=&n4;

	Node head2(9);
	Node n1b(8);
	Node n2b(2);
	Node n3b(10);
	Node n4b(11);
	head2.Left=&n1b;
	head2.Right=&n3b;
	n1b.Left=&n2b;
	n3b.Right=&n4b;

	std::cout << " the median of the two arrays is : " << std::setprecision( 2 )<< arrayMedian(&head1,&head2)<<std::endl;

	return 0;
}