#include <LiquidCrystal_I2C.h>
#include <Adafruit_NeoPixel.h>
//#include <MD_Parola.h>
//#include <MD_MAX72xx.h>
//#include <SPI.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 2
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 24
// Uncomment according to your hardware type
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
#ifdef __AVR__
#include <avr/power.h>
#endif
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
uint32_t altzeit;
float messwert, mittelwert;
#define DELAYVAL 100 // Time (in milliseconds) to pause between pixels
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A5, INPUT);
// Init
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(5, 0);
lcd.print("Laustaerke");
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
}
void loop() {
int sensorValue = analogRead(A5);
if (millis() - altzeit >= (DELAYVAL)) { // alle 100 ms messen
altzeit=millis();
mittelwert = 0.95 * mittelwert + 0.05 * sensorValue; //Anzahl Messwerte in Reihe
Serial.print (mittelwert); Serial.print('\t'); //Azsgabe Mittelwert
Serial.println(sensorValue); // Ausgabe Echtzeitwert
}
// delay(DELAYVAL);
lcd.setCursor(8, 1);
lcd.print(sensorValue);
lcd.setCursor (6, 2);
lcd.print(mittelwert);
pixels.clear(); // Set all pixel colors to 'off'
{
if (mittelwert < 1000)
{
// The first NeoPixel in a strand is #0, second is 1, all the way up
// to the count of pixels minus one.
for(int i=0; i<NUMPIXELS; i++)
{ // For each pixel...
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0, 150, 0)); //green
}
}
else if ((mittelwert >=1000) && (mittelwert <= 3000))
{
for(int i=0; i<NUMPIXELS; i++)
{ // For each pixel...
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(150, 150, 0)); //gelb
}
}
else
{
for(int i=0; i<NUMPIXELS; i++)
{ // For each pixel...
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(150, 0, 0)); //rot
}
}
}
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}