В проекте использована недорогая отладочная плата с контроллером STM32F103C8T6.
nt main(void) { initGpio(); initTimer(); initAdc(); while(1) { while(!ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC)) {} ADC_ClearFlag(ADC2, ADC_FLAG_EOC); levelAdc = ADC2->DR; if (levelAdc < MIN_ADC_LEVEL) { color = counter; } else {color = levelAdc;} if (color > MAX_ADC_LEVEL) {color = MAX_ADC_LEVEL;} if ((color >= MIN_ADC_LEVEL) & (color < (COLOR_CHANGE_PART))) { // red=max, green++, blue=min red = MAX_ADC_LEVEL; green = color * 8; blue = 0; } if ((color >= (COLOR_CHANGE_PART)) & (color < (2 * COLOR_CHANGE_PART))) { // red--, green=max, blue=min red = (COLOR_CHANGE_PART - (color - COLOR_CHANGE_PART)) * 8; green = MAX_ADC_LEVEL; blue = 0; } if ((color >= (2 * COLOR_CHANGE_PART)) & (color < (3 * COLOR_CHANGE_PART))) { // red=min, green=max, blue++ red = 0; green = MAX_ADC_LEVEL; blue = (color - (2 * COLOR_CHANGE_PART)) * 8; } if ((color >= (3 * COLOR_CHANGE_PART)) & (color < (4 * COLOR_CHANGE_PART))) { // red=min, green--, blue=max red = 0; green = (COLOR_CHANGE_PART - (color - (3 * COLOR_CHANGE_PART))) * 8; blue = MAX_ADC_LEVEL; } if ((color >= (4 * COLOR_CHANGE_PART)) & (color < (5 * COLOR_CHANGE_PART))) { // red++, green=min, blue=max red = (color - (4 * COLOR_CHANGE_PART)) * 8; green = 0; blue = MAX_ADC_LEVEL; } if ((color >= (5 * COLOR_CHANGE_PART)) & (color < (6 * COLOR_CHANGE_PART))) { // red=max, green=min, blue-- red = MAX_ADC_LEVEL; green = 0; blue = (COLOR_CHANGE_PART - (color - (5 * COLOR_CHANGE_PART))) * 8; } if (color >= (6 * COLOR_CHANGE_PART)) { // red++, green++, blue++ red = (color - 6 * COLOR_CHANGE_PART) * 4; green = (color - 6 * COLOR_CHANGE_PART) * 4; blue = (color - 6 * COLOR_CHANGE_PART) * 4; } TIM4->CCR1 = green; TIM4->CCR2 = red; TIM4->CCR3 = blue; } } // IRQ TIM3 20mS void TIM3_IRQHandler(void) { counter++; // 3000 * 20mS = 60 S if (counter >= (MAX_ADC_LEVEL - 2 * COLOR_CHANGE_PART)) {counter = 0;} TIM_ClearFlag(TIM3, TIM_FLAG_Update); }