Rev 280 | Blame | Last modification | View Log | Download | RSS feed
#include "defines.h"#include "INTERRUPTS.h"#include "I2C1.h"#include "NEOPIXEL.h"#include "DS3231.h"#include "TSL2561.h"// <editor-fold defaultstate="collapsed" desc="Configuration Registers">/* Config Register CONFIGL @ 0x8007 */#pragma config CPD = OFF // Data memory code protection is disabled#pragma config BOREN = OFF // Brown-out Reset disabled#pragma config IESO = OFF // Internal/External Switchover mode is disabled#pragma config FOSC = INTOSC // INTOSC oscillator: I/O function on CLKIN pin#pragma config FCMEN = OFF // Fail-Safe Clock Monitor is disabled#pragma config MCLRE = ON // MCLR/VPP pin function is MCLR#pragma config WDTE = OFF // WDT disabled#pragma config CP = OFF // Program memory code protection is disabled#pragma config PWRTE = OFF // PWRT disabled#pragma config CLKOUTEN = OFF // CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin/* Config Register CONFIG2 @ 0x8008 */#pragma config PLLEN = ON // 4x PLL disabled#pragma config WRT = OFF // Write protection off#pragma config STVREN = OFF // Stack Overflow or Underflow will not cause a Reset#pragma config BORV = HI // Brown-out Reset Voltage (Vbor), high trip point selected.#pragma config LVP = OFF // High-voltage on MCLR/VPP must be used for programming// </editor-fold>I2C1_DATA i2c_data;NEOPIXEL_DATA neopixel_data;TSL2561_DATA tsl2561_data;DS3231_TIME time;int main() {// Oscillator configuration (32Mhz HFINTOSC)OSCCONbits.SCS = 0b00;OSCCONbits.IRCF = 0b1110;ANSELA = 0x00; // All pins set to digital I/OAPFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5// Wait for HFINTOSC to be within 0.5% of target 32Mhzwhile (!OSCSTATbits.HFIOFS);Interrupt_Enable();I2C1_Init();I2C1_Configure_Master(I2C_1MHZ);NeoPixel_Init();NeoPixel_Offet(30);DS3231_Init();TSL2561_Init(TSL2561_ADDR_FLOAT);// You can change the gain on the fly, to adapt to brighter/dimmer light situationsTSL2561_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)// TSL2561_Set_Gain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)// Changing the integration time gives you a longer time over which to sense light// longer timelines are slower, but are good in very low light situtations!// TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium light)// TSL2561_Set_Timing(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim light)// uint16_t full, ir, vis;while(1) {// full = TSL2561_Get_Luminosity(0);// ir = TSL2561_Get_Luminosity(1);// vis = full - ir;//// NeoPixel_Clear();// for (uint8_t i = 0; i < (vis >> 11); i++) {// NeoPixel_Set(i, 0x10, 0x00, 0x00);// }// NeoPixel_Write_All();//// __delay_ms(100);DS3231_Get_Time(&time);NeoPixel_Clear();// Draw markersNeoPixel_Set(0, 0x10, 0x00, 0x00);NeoPixel_Set(5, 0x08, 0x02, 0x00);NeoPixel_Set(10, 0x08, 0x08, 0x00);NeoPixel_Set(15, 0x00, 0x10, 0x00);NeoPixel_Set(20, 0x00, 0x00, 0x10);NeoPixel_Set(25, 0x08, 0x00, 0x08);NeoPixel_Set(30, 0x10, 0x00, 0x00);NeoPixel_Set(35, 0x08, 0x02, 0x00);NeoPixel_Set(40, 0x08, 0x08, 0x00);NeoPixel_Set(45, 0x00, 0x10, 0x00);NeoPixel_Set(50, 0x00, 0x00, 0x10);NeoPixel_Set(55, 0x08, 0x00, 0x08);// Draw timeNeoPixel_Or((time.hour * 5) % 60, BLUE);NeoPixel_Or(time.min, GREEN);NeoPixel_Or(time.sec, RED);NeoPixel_Write_All();}}