Merge pull request #87 from loredan/master
Fixes to blink LED and trigger duration
This commit is contained in:
commit
8826b14248
6 changed files with 34 additions and 41 deletions
|
|
@ -91,13 +91,12 @@ update the voltMeterConstant variable in pP_config.h with the correct value
|
|||
|
||||
// Headers, variables, and functions
|
||||
#include "LightChrono.h"
|
||||
#include "pP_pins.h"
|
||||
#include <Arduino.h>
|
||||
#include <EEPROM.h>
|
||||
#include "pP_function.h"
|
||||
#include "pP_i2c.hpp"
|
||||
#include "pP_pins.h"
|
||||
#include "pP_serial.h"
|
||||
#include "pP_volatile.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
void setup() {
|
||||
// Setup PWM on voltage follower (PD3)
|
||||
|
|
@ -146,13 +145,6 @@ void setup() {
|
|||
void loop() {
|
||||
if (mainLoop.hasPassed(LOOP_DUR)) {
|
||||
mainLoop.restart();
|
||||
// Blink LED's on init
|
||||
if (BlinkCount > 0) {
|
||||
BlinkState = !BlinkState;
|
||||
digitalWriteFast(ERR_LED, BlinkState);
|
||||
// digitalWriteFast(TRG_OUT, BlinkState);
|
||||
--BlinkCount;
|
||||
}
|
||||
|
||||
// Get Serial Input
|
||||
serialInput();
|
||||
|
|
@ -188,25 +180,21 @@ void loop() {
|
|||
// Check that the piezo disk is properly connected
|
||||
pzConCheck();
|
||||
|
||||
// Blink LED's on init
|
||||
if (BlinkCount > 0) {
|
||||
BlinkState = !BlinkState;
|
||||
digitalWriteFast(ERR_LED, BlinkState);
|
||||
// digitalWriteFast(TRG_OUT, BlinkState);
|
||||
--BlinkCount;
|
||||
// } else {
|
||||
// Check for error state
|
||||
// checkError();
|
||||
} else {
|
||||
digitalWriteFast(ERR_LED, 0);
|
||||
}
|
||||
|
||||
// Print state if debug is on
|
||||
if (Debug > 0) {
|
||||
serialPrintState();
|
||||
}
|
||||
// Sets trigger output state to false after completing loop
|
||||
// digitalWriteFast(TRG_OUT, HIGH);
|
||||
sensorHReading = 0;
|
||||
}
|
||||
|
||||
// Blink LED
|
||||
if (blinkLoop.hasPassed(BLINK_DURATION) && BlinkCount > 0) {
|
||||
blinkLoop.restart();
|
||||
BlinkCount--;
|
||||
digitalWriteFast(ERR_LED, BlinkCount % 2);
|
||||
}
|
||||
|
||||
if (lastTriggerTimestamp > 0 && millis() - lastTriggerTimestamp > TRG_DUR) {
|
||||
digitalWriteFast(TRG_OUT, !LOGIC);
|
||||
lastTriggerTimestamp = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ extern uint8_t pP_i2c_address;
|
|||
#define PP_VERSION "2.3.2"
|
||||
#endif // PP_VERSION fallback if python script fails
|
||||
|
||||
#define BLINK_DURATION 100
|
||||
|
||||
void eraseEEPROM();
|
||||
void setDefaultConfig();
|
||||
void restoreConfig();
|
||||
|
|
|
|||
|
|
@ -38,12 +38,12 @@ void doubleFlash() {
|
|||
/*------------------------------------------------*/
|
||||
|
||||
void pulse() {
|
||||
digitalWriteFast(TRG_OUT, LOGIC);
|
||||
sensorHReading = 1;
|
||||
delay(TRG_DUR);
|
||||
digitalWriteFast(TRG_OUT, !LOGIC);
|
||||
Serial.println("Trig'd!");
|
||||
doubleFlash();
|
||||
if (lastTriggerTimestamp == 0) {
|
||||
digitalWriteFast(TRG_OUT, LOGIC);
|
||||
Serial.println("Trig'd!");
|
||||
doubleFlash();
|
||||
lastTriggerTimestamp = millis();
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "pP_cmd.h"
|
||||
#include "pP_volatile.h"
|
||||
#include "string.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
void parseData() {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#include "stdint.h"
|
||||
|
||||
// these variables will change on their own. Do not edit ANYTHING below this line
|
||||
volatile int sensorHReading = 0; // variable to store the value read from the sensor pin
|
||||
volatile int ADJ_FOLLOW = 0; // Variable for Follower adjustment
|
||||
volatile int ADJ_COMP = 0; // Variable for Comparator adjustment
|
||||
volatile int ERR_STATE = 0;
|
||||
|
|
@ -28,8 +27,7 @@ int VFol = 0;
|
|||
|
||||
// Error blink parameters
|
||||
|
||||
int BlinkState = 0;
|
||||
int BlinkCount = (InitCount * 2) + 1; // Multiply Blink count by 2 to handle toggle state, add one extra to make sure light is on after
|
||||
int BlinkCount = InitCount * 2; // Multiply Blink count by 2 to handle toggle state
|
||||
|
||||
// Serial Input Parsing Variables
|
||||
char inputBuffer[buffSize];
|
||||
|
|
@ -38,4 +36,7 @@ bool serialIncoming = false;
|
|||
char serialMessageIn[buffSize] = {0};
|
||||
long serialLong = 0;
|
||||
|
||||
LightChrono mainLoop;
|
||||
long lastTriggerTimestamp = 0;
|
||||
|
||||
LightChrono mainLoop;
|
||||
LightChrono blinkLoop;
|
||||
|
|
@ -5,9 +5,8 @@
|
|||
#include "stdint.h"
|
||||
|
||||
// these variables will change on their own. Do not edit ANYTHING below this line
|
||||
extern volatile int sensorHReading; // variable to store the value read from the sensor pin
|
||||
extern volatile int ADJ_FOLLOW; // Variable for Follower adjustment
|
||||
extern volatile int ADJ_COMP; // Variable for Comparator adjustment
|
||||
extern volatile int ADJ_FOLLOW; // Variable for Follower adjustment
|
||||
extern volatile int ADJ_COMP; // Variable for Comparator adjustment
|
||||
extern volatile int ERR_STATE;
|
||||
extern volatile int PZ_STATE;
|
||||
|
||||
|
|
@ -30,8 +29,7 @@ extern int VFol;
|
|||
|
||||
// Error blink parameters
|
||||
|
||||
extern int BlinkState;
|
||||
extern int BlinkCount; // Multiply Blink count by 2 to handle toggle state, add one extra to make sure light is on after
|
||||
extern int BlinkCount; // Multiply Blink count by 2 to handle toggle state, subtract one to make sure light is on after
|
||||
|
||||
// Serial Input Parsing Variables
|
||||
#define buffSize 40
|
||||
|
|
@ -42,10 +40,13 @@ extern bool serialIncoming;
|
|||
extern char serialMessageIn[buffSize];
|
||||
extern long serialLong;
|
||||
|
||||
extern long lastTriggerTimestamp;
|
||||
|
||||
//#define LOW 0
|
||||
//#define HIGH 1
|
||||
|
||||
// Task scheduler instances
|
||||
extern LightChrono mainLoop;
|
||||
extern LightChrono blinkLoop;
|
||||
|
||||
#endif // PP_VOLATILE_H
|
||||
Loading…
Reference in a new issue