Add third LED, somewhat working, but with jitter
This commit is contained in:
22
src/main.cpp
22
src/main.cpp
@@ -1,6 +1,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
static uint8_t led_duration = 4;
|
static uint8_t led_duration = 8;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function: configureTimer
|
* Function: configureTimer
|
||||||
@@ -14,7 +14,7 @@ void configureTimer()
|
|||||||
TCCR0B = 0;// same for TCCR0B
|
TCCR0B = 0;// same for TCCR0B
|
||||||
TCNT0 = 0;//initialize counter value to 0
|
TCNT0 = 0;//initialize counter value to 0
|
||||||
// set compare match register for 2khz increments
|
// set compare match register for 2khz increments
|
||||||
OCR0A = 124;// = (16*10^6) / (2000*64) - 1 (must be <256)
|
OCR0A = 4;// = (16*10^6) / (2000*64) - 1 (must be <256)
|
||||||
// turn on CTC mode
|
// turn on CTC mode
|
||||||
TCCR0A |= (1 << WGM01);
|
TCCR0A |= (1 << WGM01);
|
||||||
// Set CS01 and CS00 bits for 64 prescaler
|
// Set CS01 and CS00 bits for 64 prescaler
|
||||||
@@ -71,6 +71,7 @@ void setup()
|
|||||||
Serial.println("set output pins...");
|
Serial.println("set output pins...");
|
||||||
pinMode(2, OUTPUT);
|
pinMode(2, OUTPUT);
|
||||||
pinMode(3, OUTPUT);
|
pinMode(3, OUTPUT);
|
||||||
|
pinMode(4, OUTPUT);
|
||||||
pinMode(9, OUTPUT);
|
pinMode(9, OUTPUT);
|
||||||
pinMode(7, INPUT);
|
pinMode(7, INPUT);
|
||||||
|
|
||||||
@@ -94,6 +95,9 @@ static uint16_t led_a_counter = led_a_period;
|
|||||||
static uint16_t led_b_period = (uint16_t)-1;
|
static uint16_t led_b_period = (uint16_t)-1;
|
||||||
static uint16_t led_b_counter = led_b_period;
|
static uint16_t led_b_counter = led_b_period;
|
||||||
|
|
||||||
|
static uint16_t led_c_period = (uint16_t)-1;
|
||||||
|
static uint16_t led_c_counter = led_c_period;
|
||||||
|
|
||||||
ISR(TIMER0_COMPA_vect){
|
ISR(TIMER0_COMPA_vect){
|
||||||
iterator++;
|
iterator++;
|
||||||
|
|
||||||
@@ -108,6 +112,7 @@ ISR(TIMER0_COMPA_vect){
|
|||||||
period = iterator;
|
period = iterator;
|
||||||
led_a_period = period / 3;
|
led_a_period = period / 3;
|
||||||
led_b_period = period * 20 / 61;
|
led_b_period = period * 20 / 61;
|
||||||
|
led_c_period = period * 20 / 59;
|
||||||
iterator = 0;
|
iterator = 0;
|
||||||
rotations++;
|
rotations++;
|
||||||
}
|
}
|
||||||
@@ -127,7 +132,7 @@ ISR(TIMER0_COMPA_vect){
|
|||||||
|
|
||||||
/* Emit strobe for LED B */
|
/* Emit strobe for LED B */
|
||||||
led_b_counter--;
|
led_b_counter--;
|
||||||
if (led_b_counter < led_duration) {
|
if (led_b_counter < led_duration*6) {
|
||||||
digitalWrite(3, HIGH);
|
digitalWrite(3, HIGH);
|
||||||
if (!led_b_counter) {
|
if (!led_b_counter) {
|
||||||
led_b_counter = led_b_period;
|
led_b_counter = led_b_period;
|
||||||
@@ -135,6 +140,17 @@ ISR(TIMER0_COMPA_vect){
|
|||||||
} else {
|
} else {
|
||||||
digitalWrite(3, LOW);
|
digitalWrite(3, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Emit strobe for LED C */
|
||||||
|
led_c_counter--;
|
||||||
|
if (led_c_counter < led_duration) {
|
||||||
|
digitalWrite(4, HIGH);
|
||||||
|
if (!led_c_counter) {
|
||||||
|
led_c_counter = led_c_period;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
digitalWrite(4, LOW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|||||||
Reference in New Issue
Block a user