So I’ve setup Particle Workbench and been messing around with Manual Mode, I was wondering if someone could take a look at my code and help optimise it please…
I did try playing around with ‘waitFor’ and ‘waitUntil’ instead of using ‘Delay’ but it seemed to block the code. I tried using System_Thread Enabled to see if that fixed anything, after reading the github DeviceOS Issues but no luck.
Description
When the “Switched Input” goes High, the Tiny85 powers on the Argon using the EN Pin and sets the DigitalOutput (Pin 3) High.
Once the Argon is enabled, it reads the state of the DigitalInput (Pin D8) connected to Pin 3 of the Tiny85.
If Pin D8 is High and the Argon hasn’t published an alarm, the Argon connects to the Particle Cloud and publishes an “Alarm” message, disconnects from the Particle Cloud, and sets the ‘alarm_sent’ True.
If Pin D8 goes Low after the alarm message has been published, it then reconnects to the Particle Cloud and publishes an “OK Clear” message, disconnects from the Particle Cloud, and sets the ‘alarm_cleared’ True.
If Pin D8 is Low and the “OK Clear” message has been published, it sets the DigitalOutput (Pin D6) High, which is connected to the DigitalInput (Pin 0) of the Tiny85, powering off the Argon.
Else if, Pin D8 is Low and an alarm message hasn’t been published to the Particle Cloud, set Pin D6 High to power off the Argon.
Argon Code
SYSTEM_MODE(MANUAL);
const int Tiny85_DigitalOut = D8;
const int Argon_PWR_OFF = D6;
bool alarm_sent = false;
bool alarm_cleared = false;
// setup() runs once, when the device is first turned on.
void setup() {
pinMode(Tiny85_DigitalOut, INPUT);
digitalWrite(Tiny85_DigitalOut, LOW);
pinMode(Argon_PWR_OFF, OUTPUT);
digitalWrite(Argon_PWR_OFF, LOW);
}
// loop() runs over and over again, as quickly as it can execute.
void loop(){
delay(5000);
int Tiny85_Alarm = digitalRead(Tiny85_DigitalOut);
if (Tiny85_Alarm == HIGH && alarm_sent == false) {
Particle.connect();
}
if (Particle.connected()) {
Particle.process();
Particle.publish("ALARM", PRIVATE);
Particle.disconnect();
alarm_sent = !false;
}
if (Tiny85_Alarm == LOW && alarm_sent == !false) {
Particle.connect();
delay(10000);
Particle.process();
Particle.publish("OK Clear", PRIVATE);
delay(5000);
Particle.disconnect();
alarm_cleared = !false;
}
if (Tiny85_Alarm == LOW && alarm_cleared == !false) {
digitalWrite(Argon_PWR_OFF, HIGH);
}
else {
if (Tiny85_Alarm == LOW && alarm_sent == false) {
digitalWrite(Argon_PWR_OFF, HIGH);
}
}
}