Hello everyone,
First of all this is my first post here, i'm not fully aware of the rules for posting but I'll try to organize my question the best I can.
I'm making this WS2812B watch as a project for school, I'm using the attiny414 in combination with the tinyNeoPixel library. Everything is working fine hardware-wise so I'm able to make a LED-chase following the RTC using an external oscillator. The problem arises when I try to use my second data line to blink the other 12 LEDS. Then I just get 2 solid LED's on, and the first chase working. The chase works on both lines by the way, just not at the same time...
This is the code I have
#include <tinyNeoPixel.h>
#include <avr/sleep.h>
#define D1 PIN_PA4
#define D2 PIN_PA5
#define LED_POWER PIN_PA1
#define TEST PIN_PA2
#define NUM_LEDS 12
#define BRIGHTNESS 50
byte teller = 0;
bool ledStates[NUM_LEDS] = { false };
tinyNeoPixel strip1 = tinyNeoPixel(NUM_LEDS, D1, NEO_GRB + NEO_KHZ800);
tinyNeoPixel strip2 = tinyNeoPixel(NUM_LEDS, D2, NEO_GRB + NEO_KHZ800);
#define RTC_EXAMPLE_PERIOD 511
void setup() {
// put your setup code here, to run once:
pinModeFast(TEST, OUTPUT);
uint8_t temp;
temp = CLKCTRL.XOSC32KCTRLA;
temp &= ~CLKCTRL_ENABLE_bm;
CPU_CCP = CCP_IOREG_gc;
CLKCTRL.XOSC32KCTRLA = temp;
while (CLKCTRL.MCLKSTATUS & CLKCTRL_XOSC32KS_bm) {
;
}
temp = CLKCTRL.XOSC32KCTRLA;
temp &= ~CLKCTRL_SEL_bm;
CPU_CCP = CCP_IOREG_gc;
CLKCTRL.XOSC32KCTRLA = temp; // selecteren van externe oscillator
temp = CLKCTRL.XOSC32KCTRLA;
temp |= CLKCTRL_ENABLE_bm;
CPU_CCP = CCP_IOREG_gc;
CLKCTRL.XOSC32KCTRLA = temp; // oscillator enablen
while (RTC.STATUS > 0) {
;
}
RTC.PER = RTC_EXAMPLE_PERIOD;
RTC.CLKSEL = RTC_CLKSEL_TOSC32K_gc;
RTC.CTRLA = RTC_PRESCALER_DIV32_gc | RTC_RTCEN_bm | RTC_RUNSTDBY_bm;
cli();
// RTC.INTCTRL |= RTC_OVF_bm;
RTC.PITINTCTRL = RTC_PI_bm; /* PIT Interrupt: enabled */
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc /* RTC Clock Cycles 32768, resulting in 1Hz */
| RTC_PITEN_bm; /* Enable PIT counter: enabled */
sei();
// // LED init
strip1.begin();
strip2.begin();
strip1.setPixelColor(teller, 255, 255, 0);
strip2.setPixelColor(teller, 255, 255, 0);
ledStates[teller] = true;
strip1.show();
strip2.show();
// Sleep init
set_sleep_mode(SLEEP_MODE_PWR_DOWN); /* Set sleep mode to POWER DOWN mode */
sleep_enable(); /* Enable sleep mode, but not going to sleep yet */
}
// ISR(RTC_CNT_vect){
// RTC.INTFLAGS = RTC_OVF_bm;
// // PORTA.OUTTGL |= PIN2_bm; // toggle PA2 output voor test
// }
ISR(RTC_PIT_vect) {
RTC.PITINTFLAGS = RTC_PI_bm; /* Clear interrupt flag by writing '1' (required) */
}
void loop() {
// put your main code here, to run repeatedly:
sleep_cpu();
if (teller == 11) {
strip1.setPixelColor(teller, 0, 0, 0);
strip2.setPixelColor(teller, 0, 0, 0);
ledStates[teller] = false;
teller = -1;
}
strip1.setPixelColor(teller, 0, 0, 0);
strip2.setPixelColor(teller, 0, 0, 0);
ledStates[teller] = false;
strip1.setPixelColor(++teller, 255, 255, 0);
strip2.setPixelColor(teller, 255, 255, 0);
ledStates[teller] = true;
strip1.show();
strip2.show();
}
And a picture of my watch. any help is much appreciated!
