/* Change these values based on your calibration values */ #define Ripe 120 // Define max value that we consider sober #define underripe 400 // Define min value that we consider drunk
#define MQ3pin 0
float sensorValue; //variable to store sensor value
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
Serial.begin(9600); // sets the serial port to 9600
Serial.println("MQ3 warming up!");
delay(20000); // allow the MQ3 to warm up
}
/* Change these values based on your calibration values */
#define ripe 120 // Define max value that we consider sober
#define underripe 400 // Define min value that we consider drunk
#define MQ3pin A0
constexpr byte LedPins[] {5, 4, 3};
int sensorValue; //variable to store sensor value
void setup() {
for (auto LedPin:LedPins) pinMode(LedPin, OUTPUT);
/* pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);*/
Serial.begin(9600); // sets the serial port to 9600
Serial.println("MQ3 warming up!");
delay(20000); // allow the MQ3 to warm up
}
void loop() {
sensorValue = analogRead(MQ3pin); // read analog input pin 0
Serial.print("Sensor Value: ");
Serial.print(sensorValue);
for (auto LedPin : LedPins) digitalWrite(LedPin, LOW);
// Determine the status
switch (sensorValue) {
case 0 ... ripe:
Serial.println(" | Status: Ripe");
digitalWrite(5, HIGH);
break;
case ripe+1 ... underripe:
Serial.println(" | Status: Not quite Ripe");
digitalWrite(4, HIGH);
break;
default:
Serial.println(" | Status: Underripe");
digitalWrite(3, HIGH);
break;
}
delay(2000);
}
Hello killzone_kid
I would say that are "condensed" cases statements to do coding more easy. On the otherhand the ussage of constrain() function would be nice too.
Have a nice day and enjoy coding in C++.
Hello killzone_kid
What is the meaning of "suitable " in this context?
Does this construct violate any C++ rules?
Have a nice day and enjoy coding in C++.