aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index 8fc4dba..352fe41 100644
--- a/src/main.c
+++ b/src/main.c
@@ -56,15 +56,9 @@ void shieldConfig() {
GPIOB->PUPDR &= ~(0b11 << (PINOUT_BTN * 2));
GPIOB->PUPDR |= (0b01 << (PINOUT_BTN * 2));
- ADC1->SMPR &= ~(0x7);
- // ADC1->SMPR |= (0x7);
-
// calirate ADC1
ADC1->CR |= ADC_CR_ADCAL;
- while ((ADC1->CR & ADC_CR_ADCAL));
-
- // enable ADC V_REFINT
- ADC->CCR |= ADC_CCR_VREFEN;
+ while (ADC1->CR & ADC_CR_ADCAL);
// enable ADC1
ADC1->CR |= ADC_CR_ADEN;
@@ -101,10 +95,6 @@ unsigned int potRead() {
return result;
}
-void delay(int amount) {
- for (int i = 0; i < 500 * amount; i++) asm("nop");
-}
-
int mod(int a, int b) {
int m = a % b;
return m < 0 ? (b < 0) ? m - b : m + b : m;
@@ -121,6 +111,7 @@ int main() {
uint8_t reverse = 0;
uint8_t led = 0;
+ unsigned long cycles = 0;
button_state state = up_idle;
while (1) {
@@ -143,13 +134,18 @@ int main() {
if (state == pressed) reverse ^= 1;
- for(int j = 0; j < 4; j++) ledWrite(j, 0);
+ unsigned int delay_amount = 4e3 + 8e3 * potRead();
+ if (cycles >= delay_amount) {
+ for(int j = 0; j < 4; j++) ledWrite(j, 0);
+
+ // calculate next led index
+ led = mod(led + ((2 * reverse) - 1), 4);
- // calculate next led index
- led = mod(led + ((2 * reverse) - 1), 4);
+ ledWrite(led, 1);
- ledWrite(led, 1);
+ cycles = 0;
+ }
- delay(100 + 300 * potRead());
+ cycles += 1;
}
}