Advertisement
Simonik

Pulsy

Feb 28th, 2016
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1.  #ifndef cbi
  2.  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
  3.  #endif
  4.  #ifndef sbi
  5.  #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
  6.  #endif
  7.  
  8. #include <interval.h>
  9. #include "LowPower.h"
  10.  
  11. #define GOLOWPOWER() LowPower.idle(SLEEP_30MS, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_ON, SPI_OFF, USART0_ON, TWI_OFF)
  12.  
  13. #define LED PB5 // pin, na kterem je pripojena LED dioda
  14. Interval system1;
  15. Interval system2;
  16.  
  17. volatile int pulse1 = 0; // pocitadlo pulsu vitr - asi bude co 5s
  18. volatile int pulse2 = 0; // pocitadlo pulsu vitr - bude co 10 minut
  19.  
  20.  
  21. void setup() {
  22.  
  23.  Serial.begin(9600);
  24.  pinMode(2,  INPUT_PULLUP);
  25.  sbi(DDRB,LED); //pinMode(LED_PIN, OUTPUT); // indikacni LED dioda
  26.  attachInterrupt(0,test, CHANGE);
  27.  
  28.  # define cas1 5000 // 5 sekund
  29.  # define cas2 600000 // 10 minuta
  30.  
  31.  system1.set(cas1);
  32.  system2.set(cas2);
  33. }
  34.  
  35. void loop() {
  36.  
  37.  while (!system1.expired())
  38.  GOLOWPOWER();  
  39.  if (system1.expired())
  40.  {
  41.    Serial.print("Pocet pulsu 5s:");
  42.    Serial.println(pulse1);
  43.    pulse1=0;
  44.    system1.set(cas1);
  45.  }
  46.  
  47.  if (system2.expired())
  48.  {
  49.    Serial.print("Pocet pulsu 10 minut:");
  50.    Serial.println(pulse2);
  51.    pulse2=0;
  52.    system1.set(cas2);
  53.  }
  54.  
  55. }
  56.  
  57. void test()
  58. {
  59.  if ( digitalRead( 2 ) == LOW )
  60.  {
  61.    pulse1++;
  62.    pulse2++;
  63.    sbi(PORTB, LED); // ledka sviti
  64.  }
  65.  else
  66.  {
  67.    cbi(PORTB, LED); // ledka nesviti
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement