aboutsummaryrefslogtreecommitdiffstats
path: root/examples/test-dac.cpp
blob: ba766a460ebea26818b9df37c950b7c92e5d6faf (plain)
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
/*
 * Simple DAC test.
 *
 * Author: Marti Bolivar <mbolivar@leaflabs.com>
 *
 * This file is released into the public domain.
 */

#include "wirish.h"
#include "dac.h"

uint16 count = 0;

void setup() {
    pinMode(BOARD_LED_PIN, OUTPUT);
    digitalWrite(BOARD_LED_PIN,1);

    Serial1.begin(9600);
    Serial1.println("**** Beginning DAC test");

    Serial1.print("Init... ");
    dac_init(DAC, DAC_CH1 | DAC_CH2);
    Serial1.println("Done.");
}

void loop() {
    toggleLED();
    delay(100);

    count += 100;
    if (count > 4095) {
        count = 0;
    }

    dac_write_channel(DAC, 1, 4095 - count);
    dac_write_channel(DAC, 2, count);
}

int main(void) {
    init();
    setup();

    while (1) {
        loop();
    }
    return 0;
}