-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathmain.c
More file actions
43 lines (33 loc) · 1017 Bytes
/
main.c
File metadata and controls
43 lines (33 loc) · 1017 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libtock-sync/peripherals/adc.h>
#include <libtock-sync/services/alarm.h>
int main(void) {
printf("[Tock] ADC Sample All Channels Test\n");
// check if ADC driver exists
if (!libtocksync_adc_exists()) {
printf("No ADC driver!\n");
return -1;
}
int channel_count;
libtocksync_adc_channel_count(&channel_count);
printf("ADC driver exists with %d channels\n\n", channel_count);
while (1) {
printf("Single Samples\n");
// iterate through the channels
for (uint8_t channel = 0; channel < channel_count; channel++) {
uint16_t sample;
int err = libtocksync_adc_sample(channel, &sample);
if (err != 0) {
printf("ERROR READING ADC VALUE: %i\n", err);
}
int millivolts = (sample * 3300) / 4095;
printf("Channel %u: %d mV (raw: 0x%04x)\n", channel, millivolts, sample);
}
printf("\n");
libtocksync_alarm_delay_ms(1000);
}
return 0;
}