diff --git a/platformio.ini b/platformio.ini index 33c978d..6d54397 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,6 +17,8 @@ build_src_filter = -<.git/> -<.svn/> - - - + - - - - \ No newline at end of file + - + - + + \ No newline at end of file diff --git a/src/button_interupt/button.cpp b/src/button_interupt/button.cpp index f32fa2a..06d55a9 100644 --- a/src/button_interupt/button.cpp +++ b/src/button_interupt/button.cpp @@ -4,8 +4,6 @@ #include "button.h" -#ifdef BUTTON_INTERRUPT - ISR(INT0_vect) { PORTB = 0; @@ -43,5 +41,3 @@ void init() { void loop() { } - -#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e7eb02c..eb39cf2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,8 @@ extern void loop(); //#include "button_poll/button.h" //#include "button_interupt/button.h" //#include "trafficlight/trafficlight.h" -#include "summer/summer.h" +//#include "summer/summer.h" +#include "summer_controlled/summer.h" int main() { init(); diff --git a/src/summer/summer.cpp b/src/summer/summer.cpp index 12e18a7..145bf9b 100644 --- a/src/summer/summer.cpp +++ b/src/summer/summer.cpp @@ -15,13 +15,14 @@ void init() { TCCR0A |= (1 << WGM01); // set timer to CTC - OCR0A = 0x70; // count up to this value + OCR0A = 0x70; // count up to this value 440Hz +// OCR0A = 0x117; // count up to this value 265Hz TIMSK0 |= (1 << OCIE0A); // enable timer 0 - sei(); // enable interrupts + TCCR0B |= (1 << CS02) | (1 << CS00); // start timer and set prescaler to 1024 - TCCR0B |= (1 << CS02); // start timer and set prescaler to 256 + sei(); // enable interrupts } void loop() { diff --git a/src/summer_controlled/summer.cpp b/src/summer_controlled/summer.cpp new file mode 100644 index 0000000..5b73f61 --- /dev/null +++ b/src/summer_controlled/summer.cpp @@ -0,0 +1,65 @@ +// +// Created by servostar on 30.10.23. +// + +#include "summer.h" + +void setup_summer_it(); + +void setup_button_it(); + +ISR (TIMER0_COMPA_vect) +{ + PORTB = ~PORTB; +} + +ISR(INT0_vect) +{ + OCR0A = 18; // count up to this value 440Hz +} + +ISR(INT1_vect) +{ + OCR0A = 30; // count up to this value 265Hz +} + +void init() { + setup_summer_it(); + setup_button_it(); + sei(); // enable interrupts +} + +void setup_button_it() { + // set Port D to input (bit 2/3, remember bit 0/1 are for UART) + SET_INPUT(DDRD, DDD2); + SET_INPUT(DDRD, DDD3); + // put 5V on input (make it pull up resistor) + SET_BIT(PORTD, DDD2); + SET_BIT(PORTD, DDD3); + + // configure interrupt mode + SET_INTERRUPT_MODE(0, FALLING); + SET_INTERRUPT_MODE(1, FALLING); + + // enable interrupt 0 and 1 + ENABLE_INTERRUPT(0); + ENABLE_INTERRUPT(1); +} + +void setup_summer_it() { + DDRB = 255; + PORTB = 0; + + TCCR0A |= (1 << WGM01); // set timer to CTC + + OCR0A = 0x70; // count up to this value 440Hz +// OCR0A = 0x117; // count up to this value 265Hz + + TIMSK0 |= (1 << OCIE0A); // enable timer 0 + + TCCR0B |= (1 << CS02) | (1 << CS00); // start timer and set prescaler to 1024 +} + +void loop() { + +} diff --git a/src/summer_controlled/summer.h b/src/summer_controlled/summer.h new file mode 100644 index 0000000..4d2f081 --- /dev/null +++ b/src/summer_controlled/summer.h @@ -0,0 +1,13 @@ +// +// Created by servostar on 30.10.23. +// + +#ifndef ARDUINO_SUMMER_H +#define ARDUINO_SUMMER_H + +#include "prelude.h" + +void init(); +void loop(); + +#endif //ARDUINO_SUMMER_H