Compare commits
No commits in common. "cc123773b5e4747e362e0579a0cf4f44cf6d02e7" and "0755bcfe402d07acf736861935f90c0f3707cfa0" have entirely different histories.
cc123773b5
...
0755bcfe40
|
@ -30,28 +30,31 @@ void tickSimulation() {
|
||||||
|
|
||||||
simulatedPressure += pressureDelta;
|
simulatedPressure += pressureDelta;
|
||||||
lastTick = millis();
|
lastTick = millis();
|
||||||
|
|
||||||
|
Serial.print("Simulated pressure: ");
|
||||||
|
Serial.println(simulatedPressure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void measurePressure(float &pressureValue) {
|
void measurePressure(float &pressureValue, int pin) {
|
||||||
if (simulating) {
|
if (simulating) {
|
||||||
float adjusted = simulatedPressure + (random(-100, 100) / 100.0);
|
float adjusted = simulatedPressure + (random(-100, 100) / 100.0);
|
||||||
adjusted *= offsetMultiplier;
|
adjusted *= offsetMultiplier;
|
||||||
pressureValue = 0.99 * pressureValue + 0.01 * adjusted;
|
pressureValue = 0.99 * pressureValue + 0.01 * adjusted;
|
||||||
} else {
|
} else {
|
||||||
int sensorValue = analogRead(PRESSURE_SENSOR_PIN);
|
int sensorValue = analogRead(pin);
|
||||||
float adjusted = 0.098 * sensorValue - 16.56 + 3.58;
|
float adjusted = 0.098 * sensorValue - 16.56 + 3.58;
|
||||||
pressureValue = 0.99 * pressureValue + 0.01 * adjusted;
|
pressureValue = 0.99 * pressureValue + 0.01 * adjusted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resamplePressure(float &pressureValue) {
|
void resamplePressure(float &pressureValue, int pin) {
|
||||||
if (simulating) {
|
if (simulating) {
|
||||||
float adjusted = simulatedPressure + (random(-100, 100) / 100.0);
|
float adjusted = simulatedPressure + (random(-100, 100) / 100.0);
|
||||||
adjusted *= offsetMultiplier;
|
adjusted *= offsetMultiplier;
|
||||||
pressureValue = adjusted;
|
pressureValue = adjusted;
|
||||||
} else {
|
} else {
|
||||||
int sensorValue = analogRead(PRESSURE_SENSOR_PIN);
|
int sensorValue = analogRead(pin);
|
||||||
float adjusted = 0.098 * sensorValue - 16.56 + 3.58;
|
float adjusted = 0.098 * sensorValue - 16.56 + 3.58;
|
||||||
pressureValue = adjusted;
|
pressureValue = adjusted;
|
||||||
}
|
}
|
||||||
|
@ -61,20 +64,11 @@ void setSoleniod(int solenoidState) {
|
||||||
if (solenoidState == SOLENOID_STOP) {
|
if (solenoidState == SOLENOID_STOP) {
|
||||||
pressureChangeRate = 0.0;
|
pressureChangeRate = 0.0;
|
||||||
offsetMultiplier = 1.0;
|
offsetMultiplier = 1.0;
|
||||||
|
|
||||||
digitalWrite(RELAY1_PIN, HIGH);
|
|
||||||
digitalWrite(RELAY2_PIN, HIGH);
|
|
||||||
} else if (solenoidState == SOLENOID_INFLATE) {
|
} else if (solenoidState == SOLENOID_INFLATE) {
|
||||||
pressureChangeRate = inflatePSIPerSecond;
|
pressureChangeRate = inflatePSIPerSecond;
|
||||||
offsetMultiplier = inflateOffsetMultiplier;
|
offsetMultiplier = inflateOffsetMultiplier;
|
||||||
|
|
||||||
digitalWrite(RELAY1_PIN, LOW);
|
|
||||||
digitalWrite(RELAY2_PIN, HIGH);
|
|
||||||
} else if (solenoidState == SOLENOID_DEFLATE) {
|
} else if (solenoidState == SOLENOID_DEFLATE) {
|
||||||
pressureChangeRate = -deflatePSIPerSecond;
|
pressureChangeRate = -deflatePSIPerSecond;
|
||||||
offsetMultiplier = deflatePSIPerSecond;
|
offsetMultiplier = deflatePSIPerSecond;
|
||||||
|
|
||||||
digitalWrite(RELAY1_PIN, HIGH);
|
|
||||||
digitalWrite(RELAY2_PIN, LOW);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,10 @@
|
||||||
#define SOLENOID_INFLATE 1
|
#define SOLENOID_INFLATE 1
|
||||||
#define SOLENOID_DEFLATE 2
|
#define SOLENOID_DEFLATE 2
|
||||||
|
|
||||||
#define RELAY1_PIN 11
|
|
||||||
#define RELAY2_PIN 7
|
|
||||||
|
|
||||||
#define PRESSURE_SENSOR_PIN A0
|
|
||||||
|
|
||||||
extern float simulatedPressure;
|
|
||||||
|
|
||||||
void initSimulation();
|
void initSimulation();
|
||||||
void tickSimulation();
|
void tickSimulation();
|
||||||
void measurePressure(float &pressureValue);
|
void measurePressure(float &pressureValue, int pin);
|
||||||
void resamplePressure(float &pressureValue);
|
void resamplePressure(float &pressureValue, int pin);
|
||||||
void setSoleniod(int solenoidState);
|
void setSoleniod(int solenoidState);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,14 +16,16 @@
|
||||||
#define ENTER_BUTTON 30
|
#define ENTER_BUTTON 30
|
||||||
#define DOWN_BUTTON 27
|
#define DOWN_BUTTON 27
|
||||||
|
|
||||||
|
#define PRESSURE_SENSOR_PIN A0
|
||||||
|
|
||||||
Adafruit_FeatherOLED oled = Adafruit_FeatherOLED();
|
Adafruit_FeatherOLED oled = Adafruit_FeatherOLED();
|
||||||
|
|
||||||
//static const unsigned char PROGMEM arrow[] =
|
static const unsigned char PROGMEM arrow[] =
|
||||||
//{ B10000000,
|
{ B10000000,
|
||||||
// B11000000,
|
B11000000,
|
||||||
// B11100000,
|
B11100000,
|
||||||
// B11000000,
|
B11000000,
|
||||||
// B10000000};
|
B10000000};
|
||||||
//oled.drawBitmap(0, 1, arrow, 8, 5, 1);
|
//oled.drawBitmap(0, 1, arrow, 8, 5, 1);
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,34 +51,14 @@ enum screenStates {
|
||||||
SAY_HOLD,
|
SAY_HOLD,
|
||||||
SAY_TIMEOUT,
|
SAY_TIMEOUT,
|
||||||
SETTINGS,
|
SETTINGS,
|
||||||
|
NUM_SCREENSTATES
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* stateLabels[] = {
|
|
||||||
"BOOT_UP",
|
|
||||||
"PRESSURE",
|
|
||||||
"SET_POINT",
|
|
||||||
"INIT_RUN",
|
|
||||||
"BEGIN_RUN",
|
|
||||||
"MEASURING",
|
|
||||||
"RUNNING",
|
|
||||||
"SAY_DONE",
|
|
||||||
"SAY_CANCEL",
|
|
||||||
"SAY_HOLD",
|
|
||||||
"SAY_TIMEOUT",
|
|
||||||
"SETTINGS",
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
enum buttonStates upButton = OPEN;
|
enum buttonStates upButton = OPEN;
|
||||||
enum buttonStates enterButton = OPEN;
|
enum buttonStates enterButton = OPEN;
|
||||||
enum buttonStates downButton = OPEN;
|
enum buttonStates downButton = OPEN;
|
||||||
|
|
||||||
enum screenStates screenState = BOOT_UP;
|
|
||||||
float pressureValue = 0.0;
|
float pressureValue = 0.0;
|
||||||
int pressureSetPoint = 0;
|
|
||||||
//float initialPressure = 0.0;
|
|
||||||
//float runningPressure = 0.0;
|
|
||||||
float sampledPressure = 0.0;
|
|
||||||
|
|
||||||
int debounceValue(float value) {
|
int debounceValue(float value) {
|
||||||
static int prevValue = (int) value;
|
static int prevValue = (int) value;
|
||||||
|
@ -100,57 +82,34 @@ void setup()
|
||||||
pinMode(ENTER_BUTTON, INPUT); // Has external pullup
|
pinMode(ENTER_BUTTON, INPUT); // Has external pullup
|
||||||
pinMode(DOWN_BUTTON, INPUT_PULLUP);
|
pinMode(DOWN_BUTTON, INPUT_PULLUP);
|
||||||
|
|
||||||
pinMode(RELAY1_PIN, OUTPUT);
|
|
||||||
pinMode(RELAY2_PIN, OUTPUT);
|
|
||||||
digitalWrite(RELAY1_PIN, HIGH);
|
|
||||||
digitalWrite(RELAY2_PIN, HIGH);
|
|
||||||
|
|
||||||
#ifdef SIMULATE
|
#ifdef SIMULATE
|
||||||
initSimulation();
|
initSimulation();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
resamplePressure(pressureValue);
|
resamplePressure(pressureValue, PRESSURE_SENSOR_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
measurePressure(pressureValue);
|
measurePressure(pressureValue, PRESSURE_SENSOR_PIN);
|
||||||
pollButtons();
|
pollButtons();
|
||||||
runUI();
|
runUI();
|
||||||
logData();
|
|
||||||
|
|
||||||
#ifdef SIMULATE
|
#ifdef SIMULATE
|
||||||
tickSimulation();
|
tickSimulation();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void logData() {
|
|
||||||
static unsigned long lastLogTime = millis();
|
|
||||||
|
|
||||||
if (millis() > lastLogTime + 100) {
|
|
||||||
Serial.print("pressure: ");
|
|
||||||
Serial.print(pressureValue);
|
|
||||||
#ifdef SIMULATE
|
|
||||||
Serial.print(", simulated: ");
|
|
||||||
Serial.print(simulatedPressure);
|
|
||||||
#endif
|
|
||||||
Serial.print(", sampled: ");
|
|
||||||
Serial.print(sampledPressure);
|
|
||||||
Serial.print(", setpoint: ");
|
|
||||||
Serial.print(pressureSetPoint);
|
|
||||||
Serial.print(", state: ");
|
|
||||||
Serial.print(stateLabels[screenState]);
|
|
||||||
Serial.println("");
|
|
||||||
|
|
||||||
lastLogTime = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void runUI() {
|
void runUI() {
|
||||||
|
static enum screenStates screenState = BOOT_UP;
|
||||||
static enum screenStates nextState = BOOT_UP;
|
static enum screenStates nextState = BOOT_UP;
|
||||||
|
|
||||||
static unsigned long timer = millis();
|
static unsigned long timer = millis();
|
||||||
|
|
||||||
|
static int pressureSetPoint = 0;
|
||||||
static unsigned long startTime = millis();
|
static unsigned long startTime = millis();
|
||||||
|
//static float initialPressure = 0.0;
|
||||||
|
//static float runningPressure = 0.0;
|
||||||
|
static float sampledPressure = 0.0;
|
||||||
static bool isInflating = false;
|
static bool isInflating = false;
|
||||||
static bool isDeflating = false;
|
static bool isDeflating = false;
|
||||||
|
|
||||||
|
@ -159,6 +118,14 @@ void runUI() {
|
||||||
|
|
||||||
oled.clearDisplay();
|
oled.clearDisplay();
|
||||||
|
|
||||||
|
Serial.print("pressure: ");
|
||||||
|
Serial.print(pressureValue);
|
||||||
|
Serial.print(", sampled: ");
|
||||||
|
Serial.print(sampledPressure);
|
||||||
|
Serial.print(", setpoint: ");
|
||||||
|
Serial.print(pressureSetPoint);
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
switch (screenState) {
|
switch (screenState) {
|
||||||
case BOOT_UP:
|
case BOOT_UP:
|
||||||
if (millis() >= timer + 2000) {
|
if (millis() >= timer + 2000) {
|
||||||
|
@ -307,7 +274,7 @@ void runUI() {
|
||||||
|
|
||||||
if (millis() < timer + 500) {
|
if (millis() < timer + 500) {
|
||||||
// wait for solenoids to settle before averaging
|
// wait for solenoids to settle before averaging
|
||||||
resamplePressure(pressureValue);
|
resamplePressure(pressureValue, PRESSURE_SENSOR_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
setSoleniod(SOLENOID_STOP);
|
setSoleniod(SOLENOID_STOP);
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
#define RELAY1_PIN 11
|
|
||||||
#define RELAY2_PIN 7
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// initialize serial communications at 9600 bps:
|
|
||||||
Serial.begin(9600);
|
|
||||||
|
|
||||||
pinMode(RELAY1_PIN, OUTPUT);
|
|
||||||
pinMode(RELAY2_PIN, OUTPUT);
|
|
||||||
|
|
||||||
digitalWrite(RELAY1_PIN, LOW);
|
|
||||||
digitalWrite(RELAY2_PIN, LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
digitalWrite(RELAY1_PIN, HIGH);
|
|
||||||
delay(500);
|
|
||||||
digitalWrite(RELAY2_PIN, HIGH);
|
|
||||||
delay(500);
|
|
||||||
digitalWrite(RELAY1_PIN, LOW);
|
|
||||||
delay(500);
|
|
||||||
digitalWrite(RELAY2_PIN, LOW);
|
|
||||||
delay(500);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user