| 280 |
Kevin |
1 |
#include "defines.h"
|
|
|
2 |
#include "INTERRUPTS.h"
|
| 281 |
Kevin |
3 |
#include "I2C1.h"
|
| 280 |
Kevin |
4 |
#include "NEOPIXEL.h"
|
| 281 |
Kevin |
5 |
#include "DS3231.h"
|
|
|
6 |
#include "TSL2561.h"
|
| 280 |
Kevin |
7 |
|
|
|
8 |
// <editor-fold defaultstate="collapsed" desc="Configuration Registers">
|
|
|
9 |
/* Config Register CONFIGL @ 0x8007 */
|
|
|
10 |
#pragma config CPD = OFF // Data memory code protection is disabled
|
|
|
11 |
#pragma config BOREN = OFF // Brown-out Reset disabled
|
|
|
12 |
#pragma config IESO = OFF // Internal/External Switchover mode is disabled
|
|
|
13 |
#pragma config FOSC = INTOSC // INTOSC oscillator: I/O function on CLKIN pin
|
|
|
14 |
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor is disabled
|
|
|
15 |
#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR
|
|
|
16 |
#pragma config WDTE = OFF // WDT disabled
|
|
|
17 |
#pragma config CP = OFF // Program memory code protection is disabled
|
|
|
18 |
#pragma config PWRTE = OFF // PWRT disabled
|
|
|
19 |
#pragma config CLKOUTEN = OFF // CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
|
|
|
20 |
|
|
|
21 |
/* Config Register CONFIG2 @ 0x8008 */
|
|
|
22 |
#pragma config PLLEN = ON // 4x PLL disabled
|
|
|
23 |
#pragma config WRT = OFF // Write protection off
|
|
|
24 |
#pragma config STVREN = OFF // Stack Overflow or Underflow will not cause a Reset
|
|
|
25 |
#pragma config BORV = HI // Brown-out Reset Voltage (Vbor), high trip point selected.
|
|
|
26 |
#pragma config LVP = OFF // High-voltage on MCLR/VPP must be used for programming
|
|
|
27 |
// </editor-fold>
|
|
|
28 |
|
| 281 |
Kevin |
29 |
I2C1_DATA i2c_data;
|
| 280 |
Kevin |
30 |
NEOPIXEL_DATA neopixel_data;
|
| 281 |
Kevin |
31 |
TSL2561_DATA tsl2561_data;
|
|
|
32 |
DS3231_TIME time;
|
| 280 |
Kevin |
33 |
|
|
|
34 |
int main() {
|
|
|
35 |
// Oscillator configuration (32Mhz HFINTOSC)
|
|
|
36 |
OSCCONbits.SCS = 0b00;
|
|
|
37 |
OSCCONbits.IRCF = 0b1110;
|
|
|
38 |
|
|
|
39 |
ANSELA = 0x00; // All pins set to digital I/O
|
|
|
40 |
APFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5
|
|
|
41 |
|
|
|
42 |
// Wait for HFINTOSC to be within 0.5% of target 32Mhz
|
|
|
43 |
while (!OSCSTATbits.HFIOFS);
|
|
|
44 |
|
| 281 |
Kevin |
45 |
Interrupt_Enable();
|
| 280 |
Kevin |
46 |
|
| 281 |
Kevin |
47 |
I2C1_Init();
|
|
|
48 |
I2C1_Configure_Master(I2C_1MHZ);
|
| 280 |
Kevin |
49 |
|
| 281 |
Kevin |
50 |
NeoPixel_Init();
|
|
|
51 |
NeoPixel_Offet(30);
|
|
|
52 |
|
|
|
53 |
DS3231_Init();
|
|
|
54 |
|
|
|
55 |
TSL2561_Init(TSL2561_ADDR_FLOAT);
|
|
|
56 |
|
|
|
57 |
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
|
|
|
58 |
TSL2561_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
|
|
|
59 |
// TSL2561_Set_Gain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
|
|
|
60 |
|
|
|
61 |
// Changing the integration time gives you a longer time over which to sense light
|
|
|
62 |
// longer timelines are slower, but are good in very low light situtations!
|
|
|
63 |
// TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
|
|
|
64 |
TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)
|
|
|
65 |
// TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)
|
|
|
66 |
|
|
|
67 |
// uint16_t full, ir, vis;
|
|
|
68 |
|
| 280 |
Kevin |
69 |
while(1) {
|
| 281 |
Kevin |
70 |
// full = TSL2561_Get_Luminosity(0);
|
|
|
71 |
// ir = TSL2561_Get_Luminosity(1);
|
|
|
72 |
// vis = full - ir;
|
|
|
73 |
//
|
|
|
74 |
// NeoPixel_Clear();
|
|
|
75 |
// for (uint8_t i = 0; i < (vis >> 11); i++) {
|
|
|
76 |
// NeoPixel_Set(i, 0x10, 0x00, 0x00);
|
|
|
77 |
// }
|
|
|
78 |
// NeoPixel_Write_All();
|
|
|
79 |
//
|
|
|
80 |
// __delay_ms(100);
|
|
|
81 |
|
|
|
82 |
DS3231_Get_Time(&time);
|
|
|
83 |
NeoPixel_Clear();
|
|
|
84 |
|
|
|
85 |
// Draw markers
|
|
|
86 |
NeoPixel_Set(0, 0x10, 0x00, 0x00);
|
|
|
87 |
NeoPixel_Set(5, 0x08, 0x02, 0x00);
|
|
|
88 |
NeoPixel_Set(10, 0x08, 0x08, 0x00);
|
|
|
89 |
NeoPixel_Set(15, 0x00, 0x10, 0x00);
|
|
|
90 |
NeoPixel_Set(20, 0x00, 0x00, 0x10);
|
|
|
91 |
NeoPixel_Set(25, 0x08, 0x00, 0x08);
|
|
|
92 |
NeoPixel_Set(30, 0x10, 0x00, 0x00);
|
|
|
93 |
NeoPixel_Set(35, 0x08, 0x02, 0x00);
|
|
|
94 |
NeoPixel_Set(40, 0x08, 0x08, 0x00);
|
|
|
95 |
NeoPixel_Set(45, 0x00, 0x10, 0x00);
|
|
|
96 |
NeoPixel_Set(50, 0x00, 0x00, 0x10);
|
|
|
97 |
NeoPixel_Set(55, 0x08, 0x00, 0x08);
|
|
|
98 |
|
|
|
99 |
// Draw time
|
|
|
100 |
NeoPixel_Or((time.hour * 5) % 60, BLUE);
|
|
|
101 |
NeoPixel_Or(time.min, GREEN);
|
|
|
102 |
NeoPixel_Or(time.sec, RED);
|
| 280 |
Kevin |
103 |
NeoPixel_Write_All();
|
|
|
104 |
}
|
|
|
105 |
}
|