// Libraries #include #include #include // Pin definition #define buttonPin 1 #define microPin 2 #define thermistorPin 3 #define phototransistorPin 4 #define pixelPin 8 #define ledPin 19 Adafruit_NeoPixel pixels(1, pixelPin, NEO_GRB + NEO_KHZ800); ButtonStates button(buttonPin); void setup() { // Serial communication via USB Serial.begin(115200); // Pin instanciation (digital only) pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); // Neopixel pixels.begin(); pixels.clear(); pixels.show(); } void loop() { int microOut; microOut = mems(); // memsPlotter(microOut); float temp; temp = temperature(); int lum; lum = luminosity(); printValues(microOut, temp, lum); // Clear the pixel int clicks = button.triggerLong(); switch(clicks) { case 1: lightPixel(0,127,0); break; case 2: clearPixel(); break; } } int mems() { int micOut; micOut = analogRead(microPin); return micOut; } void memsPlotter(int micOut) { Serial.println(micOut); delay(50); } float temperature() { // From https://circuitdigest.com/microcontroller-projects/arduino-thermistor-interfacing-code-circuit float vOut; float A = 1.009249522e-03, B = 2.378405444e-04, C = 2.019202697e-07; float tempKelvin, logRt, tempCelsius, tempFarhenheit; vOut = analogRead(thermistorPin); logRt = log(10000.0 * ((1024.0 / vOut - 1))); tempKelvin = (1.0 / (A + B * logRt + C * logRt * logRt * logRt)); tempCelsius = tempKelvin - 273.15; // tempFarhenheit = (tempCelsius * 1.8) + 32.0; return tempCelsius; } int luminosity() { int lum; lum = analogRead(phototransistorPin); lum = map(lum, 0, 1024, 255, 0); return lum; } void printValues(int microValue, int tempValue, int lumValue) { // Micro Serial.print("Micro: "); Serial.println(microValue); // Thermistor Serial.print("Temperature: "); Serial.println(tempValue); // Phototransistor Serial.print("Luminosity: "); Serial.println(lumValue); delay(50); } void lightPixel(int r, int g, int b) { pixels.fill(pixels.Color(r, g, b)); pixels.show(); } void clearPixel() { pixels.fill(pixels.Color(0,0,0)); pixels.show(); } void blinkPixel(int r, int g, int b) { lightPixel(r, g, b); delay(500); clearPixel(); delay(500); }