Example #1
0
int main(void)
{
	struct sched_t sched[NUM_LEDS];
	
	init_microcontroller();
	scheduler_fill(sched, 1, 1, 1);
	for (;;)
	{
		scheduler_run(sched);
	}
}
Example #2
0
int main(void)
{
	int i, j;
	uint16_t value;
	uint8_t adc_value;  //variable store value from conversion
	struct sched_t sched[NUM_LEDS];
	init_microcontroller();
	for (;;)
	{
		adc_value = read_ADC();
		//if (adc_value > 155)
		if (adc_value > ADC_ZERO + (EPSILON / 2))
		{
			// light blue radially from center
			scheduler_fill(sched, 0, 1, 0);
			scheduler_schedule_color(&sched[0], 0, 0, 1);
			value = ADC_ZERO + EPSILON;
			for (i=1; i<NUM_LEDS && value < 256; i++)
			{
				if (adc_value > value)
					scheduler_schedule_color(&sched[i], 0, 0, 1);
				else
					break;
				value += 10;
			}			
		}			
		else if (adc_value < ADC_ZERO - (EPSILON / 2))
		{
			// light red radially from center
			scheduler_fill(sched, 0, 1, 0);
			scheduler_schedule_color(&sched[0], 1, 0, 0);
			value = ADC_ZERO - EPSILON;
			for (i=1; i<NUM_LEDS && value >= 0; i++)
			{
				if (adc_value < value)
					scheduler_schedule_color(&sched[i], 1, 0, 0);
				else
					break;
				value -= 10;
			}			
		}								
		else
		{
			// at rest. light all green
			scheduler_fill(sched, 0, 1, 0);
		}			
		
		for (i=0; i<10; i++)
			scheduler_run(sched);
	}
	
	return 0;
}
Example #3
0
int main()
{
    char buffer[20];
    int i;
    float tmp, roll_angle;
    float acc_gyro = 0, dt;
    struct Gyro1DKalman filter_roll;
    struct Gyro1DKalman filter_pitch;

    init_microcontroller();

    adc_init();
    adc_start();

    timer_init_ms();

    uart1_open();
    uart1_puts("Device initialized\n\r");

    uart1_puts("Entering main loop\n\r");

    init_Gyro1DKalman(&filter_roll, 0.0001, 0.0003, 0.69);

    while(1)
    {
        dt = timer_dt();   // time passed in s since last call

        // execute kalman filter
        tmp = PredictAccG_roll(accelero_z(), accelero_y(), accelero_x());
        ars_predict(&filter_roll, gyro_roll_rad(), dt);    // Kalman predict
        roll_angle = ars_update(&filter_roll, tmp);        // Kalman update + result (angle)

        //PrintAll(accelero_x(), accelero_y(), accelero_z(), gyro_roll_rad(), gyro_pitch_rad(), r);
        PrintForVbApp(roll_angle / 3.14*180.0, tmp);
        //PrintForStabilizer(r);
    }

    uart1_close();

    return 0;
}