Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 281 → Rev 282

/PIC Stuff/PICX_12F1840_Clock/main.c
15,7 → 15,7
#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 PWRTE = ON // PWRT enabled
#pragma config CLKOUTEN = OFF // CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
 
/* Config Register CONFIG2 @ 0x8008 */
38,12 → 38,13
ANSELA = 0x00; // All pins set to digital I/O
APFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5
WPUA = 0x00; // Disable weak pull-ups
 
// Wait for HFINTOSC to be within 0.5% of target 32Mhz
while (!OSCSTATbits.HFIOFS);
 
Interrupt_Enable();
 
I2C1_Init();
I2C1_Configure_Master(I2C_1MHZ);
 
55,8 → 56,8
TSL2561_Init(TSL2561_ADDR_FLOAT);
 
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
TSL2561_Set_Gain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
// TSL2561_Set_Gain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
// TSL2561_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!
64,42 → 65,50
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;
uint16_t full;
uint8_t multiplier, multiplier_2;
 
// time.sec = 0;
// time.min = 16;
// time.hour = 7;
// time.h_mil = 0;
// time.h_am_pm = 1;
//
// DS3231_Set_Time(&time);
 
while(1) {
// full = TSL2561_Get_Luminosity(0);
// ir = TSL2561_Get_Luminosity(1);
// vis = full - ir;
//
// ~37200 seems to be the max value at 16X gain, 101ms period
full = TSL2561_Get_Luminosity(0);
multiplier = (full / 3100) + 1; // 12 levels (1-12)
multiplier_2 = (multiplier / 7) + 1; // 2 levels (1-2)
 
// NeoPixel_Clear();
// for (uint8_t i = 0; i < (vis >> 11); i++) {
// NeoPixel_Set(i, 0x10, 0x00, 0x00);
// for (uint8_t i = 0; i < multiplier; i++) {
// NeoPixel_Set(i, 0x10, 0x00, 0x00, 1);
// }
// NeoPixel_Write_All();
//
// __delay_ms(100);
 
DS3231_Get_Time(&time);
NeoPixel_Clear();
 
// Draw markers
NeoPixel_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);
NeoPixel_Set(00, RED, multiplier_2);
NeoPixel_Set(30, RED, multiplier_2);
NeoPixel_Set(05, ORANGE, multiplier_2);
NeoPixel_Set(35, ORANGE, multiplier_2);
NeoPixel_Set(10, YELLOW, multiplier_2);
NeoPixel_Set(40, YELLOW, multiplier_2);
NeoPixel_Set(15, GREEN, multiplier_2);
NeoPixel_Set(45, GREEN, multiplier_2);
NeoPixel_Set(20, BLUE, multiplier_2);
NeoPixel_Set(50, BLUE, multiplier_2);
NeoPixel_Set(25, PURPLE, multiplier_2);
NeoPixel_Set(55, PURPLE, multiplier_2);
 
// Draw time
NeoPixel_Or((time.hour * 5) % 60, BLUE);
NeoPixel_Or(time.min, GREEN);
NeoPixel_Or(time.sec, RED);
NeoPixel_Or((time.hour * 5) % 60, BLUE, multiplier + 4);
NeoPixel_Or(time.min, GREEN, multiplier + 4);
NeoPixel_Or(time.sec, RED, multiplier + 4);
NeoPixel_Write_All();
}
}