/* * Tremolo * Yann Van Hoof */ unsigned short count; unsigned int t, times, scale; void Tempo(){ GPIO = 4; t = 0; while (GPIO.GP5 == 1){ Delay_ms(1); t++; } } void main(){ GPIO = 0; CMCON = 7; TRISIO = 34; //gpio1 en 5 als ingang ADCON0.VCFG = 0; ANSEL = 2; scale = 1; t = 1000; times = 0; count = 0; while (1){ /*----------------------------------------*/ if (ADC_read(1) > 600){ if (ADC_read(1) > 1000){ scale = 16; } else if (ADC_read(1) > 800){ scale = 8; } else{ scale = 4; } } else if (ADC_read(1) > 200){ if (ADC_read(1) > 400){ scale = 3; } else{ scale = 2; } } else { scale = 1; } /*----------------------------------------*/ GPIO = 4; while (times < ((t*10)/(scale*34))+1){ times++; Delay_ms(1); if (GPIO.GP5 == 1){ Tempo(); } } times = 0; GPIO = 0; while (times < ((t*10)/(scale*34))+1){ times++; Delay_ms(1); if (GPIO.GP5 == 1){ Tempo(); } } times = 0; } }