Skip to content

Instantly share code, notes, and snippets.

@bananu7
Created October 11, 2014 20:42
Show Gist options
  • Save bananu7/4478ff04cb68de8809db to your computer and use it in GitHub Desktop.
Save bananu7/4478ff04cb68de8809db to your computer and use it in GitHub Desktop.
int32_t n = 0;
int32_t duty = 99;
int32_t dutyChange = -1;
int32_t pulse = 100;
int32_t pulse_counter = 0;
while(1) { /* Loop forever */
//btns = kb.GetKeys(); /* Read button states */
btns = MyKeyboard_GetKeys();
n += 1;
if (n > duty) {
//MyKeyboard_Write(1);
LED_Off(1);
} else {
//MyKeyboard_Write(0);
LED_On(1);
}
if (n >= pulse) {
pulse_counter += 1;
n = 0;
}
if (pulse_counter > 20) {
duty += dutyChange;
pulse_counter = 0;
}
// loop duty
if (duty >= pulse) {
duty = pulse - 1;
dutyChange = -1;
}
if (duty <= 1) {
duty = 1;
dutyChange = 1;
}
Delay(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment