Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef cbi
- #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
- #endif
- #ifndef sbi
- #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
- #endif
- #include <interval.h>
- #include "LowPower.h"
- #define GOLOWPOWER() LowPower.idle(SLEEP_30MS, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_ON, SPI_OFF, USART0_ON, TWI_OFF)
- #define LED PB5 // pin, na kterem je pripojena LED dioda
- Interval system1;
- Interval system2;
- volatile int pulse1 = 0; // pocitadlo pulsu vitr - asi bude co 5s
- volatile int pulse2 = 0; // pocitadlo pulsu vitr - bude co 10 minut
- void setup() {
- Serial.begin(9600);
- pinMode(2, INPUT_PULLUP);
- sbi(DDRB,LED); //pinMode(LED_PIN, OUTPUT); // indikacni LED dioda
- attachInterrupt(0,test, CHANGE);
- # define cas1 5000 // 5 sekund
- # define cas2 600000 // 10 minuta
- system1.set(cas1);
- system2.set(cas2);
- }
- void loop() {
- while (!system1.expired())
- GOLOWPOWER();
- if (system1.expired())
- {
- Serial.print("Pocet pulsu 5s:");
- Serial.println(pulse1);
- pulse1=0;
- system1.set(cas1);
- }
- if (system2.expired())
- {
- Serial.print("Pocet pulsu 10 minut:");
- Serial.println(pulse2);
- pulse2=0;
- system1.set(cas2);
- }
- }
- void test()
- {
- if ( digitalRead( 2 ) == LOW )
- {
- pulse1++;
- pulse2++;
- sbi(PORTB, LED); // ledka sviti
- }
- else
- {
- cbi(PORTB, LED); // ledka nesviti
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement