You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
1.6 KiB
C
89 lines
1.6 KiB
C
#include <avr/io.h>
|
|
#include <stdint.h>
|
|
#include "avrIOhelper/io-helper.h"
|
|
#include "common.h"
|
|
|
|
uint16_t abzug_speed = 100;
|
|
|
|
void timer3_init()
|
|
{
|
|
TCCR3A |= (1<<COM3B1);
|
|
TCCR3B |= _BV(WGM33);
|
|
|
|
ICR3 = 100;
|
|
OCR3B = 50;
|
|
|
|
DDRE |= 1 << 4;
|
|
}
|
|
|
|
uint8_t get_abzug_state(){
|
|
return TCCR3B & _BV(CS31);
|
|
}
|
|
|
|
extern void send_settings(void);
|
|
void do_abzug(){
|
|
|
|
if (read_Input(BTN_ABZUG_EIN, RISING)) {
|
|
TCCR3B |= _BV(CS31);
|
|
set_Output(LED_ABZUG, ON);
|
|
#if PLC_MQTT_ENABLED
|
|
send_settings();
|
|
#endif
|
|
}
|
|
|
|
if (read_Input(BTN_ABZUG_AUS, RISING)) {
|
|
TCCR3B &= ~(_BV(CS31));
|
|
set_Output(LED_ABZUG, OFF);
|
|
#if PLC_MQTT_ENABLED
|
|
send_settings();
|
|
#endif
|
|
}
|
|
|
|
if (read_Input(BTN_ABZUG_PLUS, RISING)) {
|
|
if(abzug_speed <= 990)
|
|
abzug_speed += 10;
|
|
else
|
|
abzug_speed = 1000;
|
|
#if PLC_MQTT_ENABLED
|
|
send_settings();
|
|
#endif
|
|
}
|
|
|
|
if (read_Input(BTN_ABZUG_MINUS, RISING)) {
|
|
if(abzug_speed >= 20)
|
|
abzug_speed -= 10;
|
|
else
|
|
abzug_speed = 10;
|
|
#if PLC_MQTT_ENABLED
|
|
send_settings();
|
|
#endif
|
|
}
|
|
|
|
if (read_Input(BTN_ABZUG_PLUS_FEIN, RISING)) {
|
|
if(abzug_speed <= 999)
|
|
abzug_speed += 1;
|
|
else
|
|
abzug_speed = 1000;
|
|
#if PLC_MQTT_ENABLED
|
|
send_settings();
|
|
#endif
|
|
}
|
|
|
|
if (read_Input(BTN_ABZUG_MINUS_FEIN, RISING)) {
|
|
if(abzug_speed >= 11)
|
|
abzug_speed -= 1;
|
|
else
|
|
abzug_speed = 10;
|
|
#if PLC_MQTT_ENABLED
|
|
send_settings();
|
|
#endif
|
|
}
|
|
|
|
// 16000000/8
|
|
|
|
ICR3 = ((1.0/abzug_speed)*3.14*42.0*(1.0/5.0))*2.0*500.0*(1/1.03);
|
|
OCR3B = ICR3/2;
|
|
}
|
|
|
|
|