Here is my problem.
I have some code that worked in the past… and oddly… the core seems to be running the loaded code properly (IE; it keeps time and displays it) but… the core starts up… goes to breathing CYAN and then very quickly to breathing GREEN. At this point, It’s gone… and gets listed as offline. (So, there is no talking to it.) I have to factory reset it to get it working again, and I can upload “blink” app and it works fine… and stays breathing CYAN and shows up as online… until… I upload the following code.
//==============================================================================
// III 2222 CCCC CCCC L OOOOO CCCC K K
// I 2 C C L O O C K K
// I 222 C C L O O C KK
// I 2 C C L O O C K K
// III 22222 CCCC CCCC LLLLL OOOOO CCCC K K
//==============================================================================
//==============================================================================
// Program: I2Cclock
// Author: Pete Willard
// Version: 1.0
// Target: SparkCore
// Date: 2014/12/04
// Time: 08:14:45
// Notes:
//
// Reference:
// Used rather sketchy Sparkfun serial LED display "datasheet"
// Part # COM-11629 - Note: it's a rather dim display.
//==============================================================================
# define bitSet(value, bit)((value) |= (1UL << (bit)))
# define bitClear(value, bit)((value) &= ~(1UL << (bit)))
//=====[ CONSTANTS ]============================================================
// # define DEBUG 0 // 0 = debugging disabled, 1 = enabled
//This is the default address of the OpenSegment with both solder jumpers open
# define DISPLAY_ADDRESS1 0x71
// definitions from sparkfun for bitwise led controls (decimal/colon/dot)
# define COLON 4
# define DOT 5
// Time Sync and Time Zone settings
const int syncInterval = 60 * 60 * 8; //sync every 4 hours
static signed char const DEFAULT_TIME_ZONE = -4;
//=====[ VARIABLES ]============================================================
long millisTimer;
int lastSync = 0;
boolean colonOn = false;
boolean ampm = true;
char bits; // used to track binary values for bitwise
//=====[ SETUP ]================================================================
void setup() {
Spark.connect();
while(Spark.connected() == false) {
delay(100);
} while(Time.year() == 1970)
{
Spark.syncTime();
Spark.process();
delay(100);
}
Spark.disconnect();
while (Spark.connected() == true) {
delay(100);
Time.zone(DEFAULT_TIME_ZONE);
}
Wire.begin(); // join i2c bus as master
Wire.beginTransmission(DISPLAY_ADDRESS1); // transmit to slave device #4
Wire.write('v');
Wire.write(0x7A); // Brightness control command
Wire.write(100); // Set brightness level: 0% to 100%
Wire.endTransmission(); // stop transmitting
}
//=====[ MAIN PROCESS LOOP ]====================================================
void loop() {
ampm = Time.isAM();
showTime();
delay(1000);
adjustTime();
}
//==============================================================================
void adjustTime() {
if (lastSync + syncInterval < Time.now()) {
Spark.syncTime();
lastSync = Time.now();
}
}
//==============================================================================
//==============================================================================
// Must be called after a "begin.transmission()" command.
//==============================================================================
void colonFlash() {
//Blink the colon every other second
if (colonOn == true) {
colonOn = false;
bitClear(bits, COLON);
} else {
colonOn = true;
bitSet(bits, COLON);
}
Wire.write(0x77); // control command
Wire.write(bits); // Turns on/off colon
}
//==============================================================================
// Must be called after a "begin.transmission()" command.
//==============================================================================
void setPM() {
if (ampm == true) {
bitClear(bits, DOT);
} else {
bitSet(bits, DOT);
}
Wire.write(0x77); // control command
Wire.write(bits); // Turns on AM/PM
}
//==============================================================================
void showTime() {
char out[] = {
0,
0,
0,
0
}; // place holder for time array
char hour = Time.hourFormat12();
char min = Time.minute();
sprintf(out, "%2d%02d", hour, min); // format current time into char array
Wire.beginTransmission(DISPLAY_ADDRESS1); // begin I2C transmit to device
setPM();
colonFlash();
for (byte x = 0; x < 4; x++)
Wire.write(out[x]); //Send a character from the array out over I2C
Wire.endTransmission(); //Stop I2C transmission
}
I am really not sure what changed… I’d like to fix my code somehow so it stops going offline and breathing GREEN.
pw