-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c.bak
87 lines (61 loc) · 1.54 KB
/
main.c.bak
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* FF:Actuator_2018.c
*
* Created: 21/12/17 22:00
* Author : Sivert
*/
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
//#include <stdlib.h>
//#include <stdint.h>
#include <avr/io.h>
#include <util/delay.h>
#include <math.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <string.h>
#include "UniversalModuleDrivers/timer.h"
#include "UniversalModuleDrivers/rgbled.h"
#include "ActuatorDrivers/i2c_master.h"
#include "ActuatorDrivers/actuator.h"
#include "ActuatorDrivers/ads_1115.h"
#include "AVR-UART-lib/usart.h"
volatile int16_t adcReading = 0;
int main (void)
{
DDRE |= (1 <<PE4 ) | (1 <<PE5 );
TCCR3B |=(1<<CS00); //NO PRESCALER
TCCR3A |= (1<<COM3B1) |(1<<COM3C0) | (1<<COM3C1) | (1<<WGM31); //COM3B clear on comp. match, omvendt com3c |(WGM30<<1)| |
TCCR3B |= (1<<WGM32) |(1<<WGM33);
ICR3 = 256;
rgbled_init();
rgbled_turn_on(LED_ALL);
uint16_t duty = 140;//lave verdier = innover |
i2c_init();
ads_1115_write_config();
uart_init(BAUD_CALC(500000)); // 8n1 transmission is set as default
sei();
while(1){
adcReading=ads_1115_get_reading();
if (adcReading < 100)
duty=170;
if (adcReading > 20000)
duty=100;
rgbled_toggle(LED_ALL);
_delay_ms(40);
actuator_pwmSpeed(duty);
_delay_ms(30);
//actuator_out();
_delay_ms(30);
uart_putint(duty);
uart_puts("\r\n");
//_delay_ms(1000);
if(uart_AvailableBytes()!=0){
duty=uart_getint();
uart_flush();
}
}
/* Insert application code here, after the board has been initialized. */
}