Added led indicators
This commit is contained in:
parent
ed421346a9
commit
42554a57da
@ -17,6 +17,8 @@
|
||||
#define TX_PIN 7 // SoftwareSerial TX pin
|
||||
#define SLAVE_ID 101
|
||||
#define SERIAL_BAUDRATE 9600
|
||||
#define LED_A_PID 3
|
||||
#define LED_B_PID 5
|
||||
|
||||
// Try to select the best SD card configuration.
|
||||
#define SPI_CLOCK SD_SCK_MHZ(50)
|
||||
@ -38,8 +40,22 @@ ModbusMaster node;
|
||||
unsigned long lastRefreshTime = 0;
|
||||
bool headerWritten = false;
|
||||
|
||||
void flicker(uint8_t pin ,uint8_t times , uint16_t speed ) {
|
||||
for (int i = 0; i < times; i++) {
|
||||
digitalWrite(pin, HIGH);
|
||||
delay(speed);
|
||||
digitalWrite(pin, LOW);
|
||||
delay(speed);
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED_A_PID, OUTPUT);
|
||||
pinMode(LED_B_PID, OUTPUT);
|
||||
digitalWrite(LED_A_PID, LOW);
|
||||
digitalWrite(LED_B_PID, HIGH);
|
||||
|
||||
Serial.begin(SERIAL_BAUDRATE); // For debugging
|
||||
Serial.println(F("Startup \n"));
|
||||
|
||||
@ -47,6 +63,7 @@ void setup()
|
||||
if (!rtc.begin())
|
||||
{
|
||||
Serial.println(F("Couldn't find RTC\n"));
|
||||
flicker(LED_B_PID,4,500); //4 times on LED b is RTC Error
|
||||
}
|
||||
|
||||
if (rtc.lostPower())
|
||||
@ -54,6 +71,7 @@ void setup()
|
||||
Serial.println(F("RTC lost power, let's set the time!\n"));
|
||||
// Comment out the following line once the time is set to avoid resetting on every start
|
||||
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
|
||||
flicker(LED_B_PID,4,100); //4 times fast on LED b is RTC reset
|
||||
}
|
||||
|
||||
Serial.print(F("Time: "));
|
||||
@ -73,6 +91,7 @@ void setup()
|
||||
if (!sd.begin(SD_CONFIG))
|
||||
{
|
||||
sd.initErrorHalt(&Serial);
|
||||
flicker(LED_B_PID,2,500); //2 Times slow, SD Card initilize error
|
||||
return;
|
||||
}
|
||||
Serial.println(F("SD card initialized.\n"));
|
||||
@ -86,18 +105,21 @@ void setup()
|
||||
node.begin(SLAVE_ID, modbusSerial);
|
||||
node.preTransmission(preTransmission);
|
||||
node.postTransmission(postTransmission);
|
||||
flicker(LED_A_PID,2,100);
|
||||
}
|
||||
|
||||
void preTransmission()
|
||||
{
|
||||
// Serial.println(F("Transmitting Start"));
|
||||
digitalWrite(DE_RE_PIN, HIGH); // Enable RS485 transmit
|
||||
digitalWrite(LED_A_PID, HIGH);
|
||||
}
|
||||
|
||||
void postTransmission()
|
||||
{
|
||||
|
||||
digitalWrite(DE_RE_PIN, LOW); // Disable RS485 transmit
|
||||
digitalWrite(LED_A_PID, LOW);
|
||||
// Serial.println(F("Transmitting End"));
|
||||
}
|
||||
|
||||
@ -160,6 +182,7 @@ void loop()
|
||||
Serial.print("\n");
|
||||
if (!dataFile.open(filename.c_str(), FILE_WRITE))
|
||||
{
|
||||
flicker(LED_B_PID,6,100); //Six quick flickers. SD Card error
|
||||
Serial.println(F("Failed to Open Card "));
|
||||
}
|
||||
if (!headerWritten)
|
||||
@ -173,6 +196,7 @@ void loop()
|
||||
dataFile.print(",");
|
||||
}
|
||||
headerWritten = true;
|
||||
flicker(LED_A_PID,50,10); //10 flickers, written header
|
||||
}
|
||||
primeFileDate();
|
||||
Serial.print("\n");
|
||||
@ -242,7 +266,7 @@ void loop()
|
||||
|
||||
Serial.print(F("\n\n"));
|
||||
|
||||
delay(100);
|
||||
flicker(LED_A_PID,4,10); //Cycle written 4 quick flickers
|
||||
}
|
||||
|
||||
// // Check if the read was successful
|
||||
|
Loading…
Reference in New Issue
Block a user