mirror of
https://github.com/NEBULAIR/arduinoponics.git
synced 2026-03-10 08:51:16 +00:00
First version of the blinking LEDS with interrupts.
Blinks on and off every 10 seconds. Next step is to have day and night cycles
This commit is contained in:
48
arduino/ledCycleInterrupt/ledCycleInterrupt.ino
Normal file
48
arduino/ledCycleInterrupt/ledCycleInterrupt.ino
Normal file
@@ -0,0 +1,48 @@
|
||||
// Arduino timer CTC interrupt example
|
||||
//
|
||||
// avr-libc library includes
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#define LEDPIN 8
|
||||
|
||||
volatile byte seconds;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LEDPIN, OUTPUT);
|
||||
// initialize Timer1
|
||||
cli(); // disable global interrupts
|
||||
TCCR1A = 0; // set entire TCCR1A register to 0
|
||||
TCCR1B = 0; // same for TCCR1B
|
||||
|
||||
// set compare match register to desired timer count:
|
||||
OCR1A = 15624;
|
||||
|
||||
// turn on CTC mode:
|
||||
TCCR1B |= (1 << WGM12);
|
||||
|
||||
// Set CS10 and CS12 bits for 1024 prescaler:
|
||||
TCCR1B |= (1 << CS10);
|
||||
TCCR1B |= (1 << CS12);
|
||||
|
||||
// enable timer compare interrupt:
|
||||
TIMSK1 |= (1 << OCIE1A);
|
||||
|
||||
// enable global interrupts:
|
||||
sei();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// main program
|
||||
}
|
||||
|
||||
ISR(TIMER1_COMPA_vect)
|
||||
{
|
||||
seconds++;
|
||||
if(seconds == 10)
|
||||
{
|
||||
seconds = 0;
|
||||
digitalWrite(LEDPIN, !digitalRead(LEDPIN));
|
||||
}
|
||||
}
|
||||
BIN
schematics/ledstrip.fzz
Normal file
BIN
schematics/ledstrip.fzz
Normal file
Binary file not shown.
Reference in New Issue
Block a user