-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpot.c
65 lines (58 loc) · 1.74 KB
/
pot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "Arduino.h"
#include "wvr_pins.h"
#include "pot.h"
#define POT_PIN D8
int sort(const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
uint32_t adc_reading = 0;
void onPot_default(uint32_t raw_val){}
static void adc_task(void* arg)
{
int percent = 0;
for(;;) {
// uint32_t samples[30];
// uint32_t acc = 0;
// for(int i=0;i<30;i++){
// samples[i] = analogRead(39) >> 4;
// }
// // sort
// qsort(samples,30,sizeof(uint32_t),sort);
// // log_i("sorted:");
// // for(int i=0;i<30;i++){
// // log_i("%u",samples[i]);
// // }
// acc = samples[10];
// for(int i=11;i<20;i++){
// acc += samples[i];
// acc = acc/2;
// }
// log_i("average : %u",acc);
uint32_t new_adc_reading = analogRead(POT_PIN);
// if(new_adc_reading != adc_reading)
// {
// adc_reading = new_adc_reading;
// log_i("pot : %u", adc_reading);
// }
onPot(new_adc_reading);
pinMode(POT_PIN,OUTPUT);
digitalWrite(POT_PIN,HIGH);
pinMode(POT_PIN, INPUT);
// log_i("%u",adc_reading >> 5);
// int new_percent = adc_reading / (0b111111111111 / 100);
// if(new_percent != percent)
// {
// percent = new_percent;
// printf("%d percent\n", new_percent);
// }
vTaskDelay(pdMS_TO_TICKS(100));
}
}
void pot_init(void){
// analogSetWidth(8);
// analogSetCycles(8);
// analogSetSamples(4);
// xTaskCreate(&adc_task, "adc_task", 1024 * 4, NULL, 3, NULL);
onPot = onPot_default;
xTaskCreatePinnedToCore(&adc_task, "adc_task", 1024 * 4, NULL, 3, NULL, 0);
}