infinityledclock/vscode/LEDClock/src/main.cpp

90 lines
2.7 KiB
C++

#include <Arduino.h>
#include "clockelements.hpp"
const unsigned int PIN_BUZZER = 9;
const unsigned int PIN_PIXELS = 6;
const unsigned int NUM_RING_PIXELS = 180;
const unsigned int NUM_POINTER_PIXELS = 6;
const unsigned int NUM_POINTERS = 12;
const unsigned int NUM_POINTERS_PIXELS = NUM_POINTER_PIXELS * NUM_POINTERS;
const unsigned int NUM_NUMBERS = 12;
const unsigned int NUM_NUMPER_PIXELS[NUM_NUMBERS] = {2,4,4,4,4,4,4,4,4,4,4,5};
const unsigned int NUM_NUMBERS_PIXELS = NUM_NUMPER_PIXELS[0] + NUM_NUMPER_PIXELS[1] + NUM_NUMPER_PIXELS[2];
const unsigned int NUM_ALL_PIXELS = NUM_RING_PIXELS + NUM_POINTERS_PIXELS + NUM_NUMBERS_PIXELS;
Adafruit_NeoPixel pixels(NUM_ALL_PIXELS, PIN_PIXELS, NEO_GRB + NEO_KHZ800);
elements number[NUM_NUMBERS];
elements pointer[NUM_POINTERS];
uint16_t color_numbers, color_pointers_hour = 0;
void init_numbers() {
// init all the numbers
unsigned int current_first_led = NUM_RING_PIXELS + NUM_POINTERS_PIXELS;
for(unsigned int num = 0; num < NUM_NUMBERS; num++)
{
//number[num] = new numbers(&pixels, current_first_led, NUM_NUMPER_PIXELS[num]);
number[num].init(&pixels, current_first_led, NUM_NUMPER_PIXELS[num],false);
number[num].clean();
current_first_led =+ NUM_NUMPER_PIXELS[num];
}
}
void init_pointers() {
// init all the pointers - each as 6 leds, starts at 12,11,10 ... 1, each even is inversed (goes from outside into center)
unsigned int current_first_led = NUM_RING_PIXELS;
bool is_even = false;
for(unsigned int num = NUM_POINTERS-1; num >= 0; num--)
{
is_even = num%2==0? true:false;
pointer[num].init(&pixels, current_first_led, NUM_POINTER_PIXELS ,is_even);
pointer[num].clean();
current_first_led =+ NUM_POINTER_PIXELS;
}
}
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pixels.begin();
pixels.clear();
pixels.show();
Serial.print("hallo");
color_pointers_hour = 0;
color_numbers = 65535;
Serial.print("hallo");
init_numbers();
Serial.print("hallo");
init_pointers();
Serial.print("hallo");
}
void loop() {
unsigned int hour = 0;
for(unsigned int minute = 0; minute<60; minute++)
{
number[hour].fill(color_numbers,255,255);
//pointer[hour].fill(color_pointers_hour);
pointer[hour].ffill(color_pointers_hour, minute/(60/NUM_POINTER_PIXELS));
pixels.show();
tone(PIN_BUZZER, 1000, 100);
delay(50000);
number[hour].clean();
pointer[hour].clean();
pixels.show();
hour = minute == 59 ? hour+1 : hour;
hour = hour > 11 ? 0 : hour;
Serial.println(hour);
Serial.println(minute);
}
}