forked from dllud/rr-avr-os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
63 lines (53 loc) · 1.71 KB
/
example.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
/*
* example.c
* Copyright (C) 2013 David Ludovino [email protected]
*
* Uses various of the hardware abstraction functions provided by rr-avr-os.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/* Global includes */
#include "sysmods/node.h"
/* Global inclues for AVR */
/* Includes specific to this module */
#include "example.h"
#include "sysmods/pwm.h"
#include "sysmods/digitalrw.h"
#include "sysmods/adc.h"
#define CHANGE_PWM_INTERVAL 2 // * 100 = 200 ms
#define READ_ADC_INTERVAL 20 // seconds
#define BUTTON_PORT PIND
#define BUTTON_PIN PIND4
#define LED_PORT PORTD
#define LED_PIN PORTD2
#define VOLTAGE_DIVIDER_PIN PINC0
/* Global varibales ::vars **/
uint8_t EXAMPLE_timer_pwm; /* 100 ms*/
uint8_t EXAMPLE_timer_adc; /* 1 s*/
/* Local variables **/
uint8_t pwm_value;
uint8_t second;
void EXAMPLE_init(void) { }
void EXAMPLE_task(void) {
if(DIGITALRW_read(BUTTON_PORT, BUTTON_PIN))
DIGITALRW_write(LED_PORT, LED_PIN, 1);
else
DIGITALRW_write(LED_PORT, LED_PIN, 0);
if(EXAMPLE_timer_pwm >= CHANGE_PWM_INTERVAL) {
EXAMPLE_timer_pwm = 0;
printf("Writing %u to the PWM pin.\n", pwm_value);
PWM_write(EXAMPLE_PWM_PIN, pwm_value);
pwm_value++;
}
if(EXAMPLE_timer_adc >= READ_ADC_INTERVAL) {
EXAMPLE_timer_adc = 0;
printf("\t\t\t\tVoltage divider reads: %u\n", ADC_read_10bit(VOLTAGE_DIVIDER_PIN));
}
}